ai-hero-cli 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin.js +67704 -0
- package/package.json +7 -50
- package/LICENSE +0 -21
- package/README.md +0 -3
- package/dist/bin.d.ts +0 -1
- package/dist/bin.js +0 -4
- package/dist/bin.js.map +0 -1
- package/dist/command.d.ts +0 -2
- package/dist/command.js +0 -114
- package/dist/command.js.map +0 -1
- package/dist/config.d.ts +0 -15
- package/dist/config.js +0 -52
- package/dist/config.js.map +0 -1
- package/dist/model.d.ts +0 -6
- package/dist/model.js +0 -26
- package/dist/model.js.map +0 -1
- package/docs/tsconfig/allowArbitraryExtensions.md +0 -38
- package/docs/tsconfig/allowImportingTsExtensions.md +0 -9
- package/docs/tsconfig/allowJs.md +0 -41
- package/docs/tsconfig/allowSyntheticDefaultImports.md +0 -56
- package/docs/tsconfig/allowUmdGlobalAccess.md +0 -8
- package/docs/tsconfig/allowUnreachableCode.md +0 -40
- package/docs/tsconfig/allowUnusedLabels.md +0 -23
- package/docs/tsconfig/alwaysStrict.md +0 -8
- package/docs/tsconfig/assumeChangesOnlyAffectDirectDependencies.md +0 -8
- package/docs/tsconfig/baseUrl.md +0 -26
- package/docs/tsconfig/charset.md +0 -7
- package/docs/tsconfig/checkJs.md +0 -40
- package/docs/tsconfig/clean.md +0 -6
- package/docs/tsconfig/composite.md +0 -17
- package/docs/tsconfig/customConditions.md +0 -41
- package/docs/tsconfig/declaration.md +0 -32
- package/docs/tsconfig/declarationDir.md +0 -36
- package/docs/tsconfig/declarationMap.md +0 -9
- package/docs/tsconfig/diagnostics.md +0 -8
- package/docs/tsconfig/disableFilenameBasedTypeAcquisition.md +0 -16
- package/docs/tsconfig/disableReferencedProjectLoad.md +0 -8
- package/docs/tsconfig/disableSizeLimit.md +0 -6
- package/docs/tsconfig/disableSolutionSearching.md +0 -8
- package/docs/tsconfig/disableSourceOfProjectReferenceRedirect.md +0 -7
- package/docs/tsconfig/downlevelIteration.md +0 -100
- package/docs/tsconfig/emitBOM.md +0 -8
- package/docs/tsconfig/emitDeclarationOnly.md +0 -11
- package/docs/tsconfig/emitDecoratorMetadata.md +0 -81
- package/docs/tsconfig/enable.md +0 -14
- package/docs/tsconfig/erasableSyntaxOnly.md +0 -65
- package/docs/tsconfig/esModuleInterop.md +0 -74
- package/docs/tsconfig/exactOptionalPropertyTypes.md +0 -37
- package/docs/tsconfig/exclude.md +0 -11
- package/docs/tsconfig/excludeDirectories.md +0 -14
- package/docs/tsconfig/excludeFiles.md +0 -14
- package/docs/tsconfig/experimentalDecorators.md +0 -11
- package/docs/tsconfig/explainFiles.md +0 -54
- package/docs/tsconfig/extendedDiagnostics.md +0 -9
- package/docs/tsconfig/extends.md +0 -49
- package/docs/tsconfig/fallbackPolling.md +0 -11
- package/docs/tsconfig/files.md +0 -26
- package/docs/tsconfig/force.md +0 -6
- package/docs/tsconfig/forceConsistentCasingInFileNames.md +0 -10
- package/docs/tsconfig/generateCpuProfile.md +0 -15
- package/docs/tsconfig/generateTrace.md +0 -6
- package/docs/tsconfig/importHelpers.md +0 -46
- package/docs/tsconfig/importsNotUsedAsValues.md +0 -16
- package/docs/tsconfig/include.md +0 -66
- package/docs/tsconfig/incremental.md +0 -10
- package/docs/tsconfig/inlineSourceMap.md +0 -35
- package/docs/tsconfig/inlineSources.md +0 -36
- package/docs/tsconfig/isolatedDeclarations.md +0 -8
- package/docs/tsconfig/isolatedModules.md +0 -77
- package/docs/tsconfig/jsx.md +0 -111
- package/docs/tsconfig/jsxFactory.md +0 -43
- package/docs/tsconfig/jsxFragmentFactory.md +0 -69
- package/docs/tsconfig/jsxImportSource.md +0 -95
- package/docs/tsconfig/keyofStringsOnly.md +0 -8
- package/docs/tsconfig/lib.md +0 -75
- package/docs/tsconfig/libReplacement.md +0 -22
- package/docs/tsconfig/listEmittedFiles.md +0 -42
- package/docs/tsconfig/listFiles.md +0 -40
- package/docs/tsconfig/locale.md +0 -26
- package/docs/tsconfig/mapRoot.md +0 -18
- package/docs/tsconfig/maxNodeModuleJsDepth.md +0 -11
- package/docs/tsconfig/module.md +0 -125
- package/docs/tsconfig/moduleDetection.md +0 -15
- package/docs/tsconfig/moduleResolution.md +0 -13
- package/docs/tsconfig/moduleSuffixes.md +0 -26
- package/docs/tsconfig/newLine.md +0 -6
- package/docs/tsconfig/noCheck.md +0 -6
- package/docs/tsconfig/noEmit.md +0 -10
- package/docs/tsconfig/noEmitHelpers.md +0 -38
- package/docs/tsconfig/noEmitOnError.md +0 -8
- package/docs/tsconfig/noErrorTruncation.md +0 -45
- package/docs/tsconfig/noFallthroughCasesInSwitch.md +0 -22
- package/docs/tsconfig/noImplicitAny.md +0 -26
- package/docs/tsconfig/noImplicitOverride.md +0 -66
- package/docs/tsconfig/noImplicitReturns.md +0 -17
- package/docs/tsconfig/noImplicitThis.md +0 -28
- package/docs/tsconfig/noImplicitUseStrict.md +0 -7
- package/docs/tsconfig/noLib.md +0 -9
- package/docs/tsconfig/noPropertyAccessFromIndexSignature.md +0 -57
- package/docs/tsconfig/noResolve.md +0 -9
- package/docs/tsconfig/noStrictGenericChecks.md +0 -20
- package/docs/tsconfig/noUncheckedIndexedAccess.md +0 -53
- package/docs/tsconfig/noUncheckedSideEffectImports.md +0 -52
- package/docs/tsconfig/noUnusedLocals.md +0 -15
- package/docs/tsconfig/noUnusedParameters.md +0 -15
- package/docs/tsconfig/out.md +0 -9
- package/docs/tsconfig/outDir.md +0 -39
- package/docs/tsconfig/outFile.md +0 -11
- package/docs/tsconfig/paths.md +0 -39
- package/docs/tsconfig/plugins.md +0 -17
- package/docs/tsconfig/preserveConstEnums.md +0 -58
- package/docs/tsconfig/preserveSymlinks.md +0 -10
- package/docs/tsconfig/preserveValueImports.md +0 -18
- package/docs/tsconfig/preserveWatchOutput.md +0 -6
- package/docs/tsconfig/pretty.md +0 -7
- package/docs/tsconfig/reactNamespace.md +0 -6
- package/docs/tsconfig/references.md +0 -9
- package/docs/tsconfig/removeComments.md +0 -33
- package/docs/tsconfig/resolveJsonModule.md +0 -44
- package/docs/tsconfig/resolvePackageJsonExports.md +0 -8
- package/docs/tsconfig/resolvePackageJsonImports.md +0 -8
- package/docs/tsconfig/rewriteRelativeImportExtensions.md +0 -8
- package/docs/tsconfig/rootDir.md +0 -66
- package/docs/tsconfig/rootDirs.md +0 -66
- package/docs/tsconfig/skipDefaultLibCheck.md +0 -6
- package/docs/tsconfig/skipLibCheck.md +0 -19
- package/docs/tsconfig/sourceMap.md +0 -39
- package/docs/tsconfig/sourceRoot.md +0 -18
- package/docs/tsconfig/stopBuildOnErrors.md +0 -6
- package/docs/tsconfig/strict.md +0 -11
- package/docs/tsconfig/strictBindCallApply.md +0 -34
- package/docs/tsconfig/strictBuiltinIteratorReturn.md +0 -6
- package/docs/tsconfig/strictFunctionTypes.md +0 -55
- package/docs/tsconfig/strictNullChecks.md +0 -58
- package/docs/tsconfig/strictPropertyInitialization.md +0 -29
- package/docs/tsconfig/stripInternal.md +0 -60
- package/docs/tsconfig/suppressExcessPropertyErrors.md +0 -16
- package/docs/tsconfig/suppressImplicitAnyIndexErrors.md +0 -25
- package/docs/tsconfig/synchronousWatchDirectory.md +0 -14
- package/docs/tsconfig/target.md +0 -18
- package/docs/tsconfig/traceResolution.md +0 -7
- package/docs/tsconfig/tsBuildInfoFile.md +0 -17
- package/docs/tsconfig/typeAcquisition.md +0 -37
- package/docs/tsconfig/typeRoots.md +0 -21
- package/docs/tsconfig/types.md +0 -40
- package/docs/tsconfig/useDefineForClassFields.md +0 -10
- package/docs/tsconfig/useUnknownInCatchVariables.md +0 -21
- package/docs/tsconfig/verbatimModuleSyntax.md +0 -148
- package/docs/tsconfig/verbose.md +0 -6
- package/docs/tsconfig/watchDirectory.md +0 -10
- package/docs/tsconfig/watchFile.md +0 -12
- package/prompts/hows-my-tsconfig-score.md +0 -29
- package/prompts/hows-my-tsconfig.md +0 -75
package/docs/tsconfig/checkJs.md
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
display: 'Check JS'
|
|
3
|
-
oneline: 'Enable error reporting in type-checked JavaScript files.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
Works in tandem with [`allowJs`](#allowJs). When `checkJs` is enabled then errors are reported in JavaScript files. This is
|
|
7
|
-
the equivalent of including `// @ts-check` at the top of all JavaScript files which are included in your project.
|
|
8
|
-
|
|
9
|
-
For example, this is incorrect JavaScript according to the `parseFloat` type definition which comes with TypeScript:
|
|
10
|
-
|
|
11
|
-
```js
|
|
12
|
-
// parseFloat only takes a string
|
|
13
|
-
module.exports.pi = parseFloat(3.142);
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
When imported into a TypeScript module:
|
|
17
|
-
|
|
18
|
-
```ts twoslash
|
|
19
|
-
// @allowJs
|
|
20
|
-
// @filename: constants.js
|
|
21
|
-
module.exports.pi = parseFloat(3.142);
|
|
22
|
-
|
|
23
|
-
// @filename: index.ts
|
|
24
|
-
import { pi } from './constants';
|
|
25
|
-
console.log(pi);
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
You will not get any errors. However, if you turn on `checkJs` then you will get error messages from the JavaScript file.
|
|
29
|
-
|
|
30
|
-
```ts twoslash
|
|
31
|
-
// @errors: 2345
|
|
32
|
-
// @allowjs: true
|
|
33
|
-
// @checkjs: true
|
|
34
|
-
// @filename: constants.js
|
|
35
|
-
module.exports.pi = parseFloat(3.142);
|
|
36
|
-
|
|
37
|
-
// @filename: index.ts
|
|
38
|
-
import { pi } from './constants';
|
|
39
|
-
console.log(pi);
|
|
40
|
-
```
|
package/docs/tsconfig/clean.md
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
display: 'Composite'
|
|
3
|
-
oneline: 'Enable constraints that allow a TypeScript project to be used with project references.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
The `composite` option enforces certain constraints which make it possible for build tools (including TypeScript
|
|
7
|
-
itself, under `--build` mode) to quickly determine if a project has been built yet.
|
|
8
|
-
|
|
9
|
-
When this setting is on:
|
|
10
|
-
|
|
11
|
-
- The [`rootDir`](#rootDir) setting, if not explicitly set, defaults to the directory containing the `tsconfig.json` file.
|
|
12
|
-
|
|
13
|
-
- All implementation files must be matched by an [`include`](#include) pattern or listed in the [`files`](#files) array. If this constraint is violated, `tsc` will inform you which files weren't specified.
|
|
14
|
-
|
|
15
|
-
- [`declaration`](#declaration) defaults to `true`
|
|
16
|
-
|
|
17
|
-
You can find documentation on TypeScript projects in [the handbook](https://www.typescriptlang.org/docs/handbook/project-references.html).
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
display: 'Custom Conditions'
|
|
3
|
-
oneline: 'Conditions to set in addition to the resolver-specific defaults when resolving imports.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
`--customConditions` takes a list of additional [conditions](https://nodejs.org/api/packages.html#nested-conditions) that should succeed when TypeScript resolves from an [`exports`](https://nodejs.org/api/packages.html#exports) or [`imports`](https://nodejs.org/api/packages.html#imports) field of a `package.json`.
|
|
7
|
-
These conditions are added to whatever existing conditions a resolver will use by default.
|
|
8
|
-
|
|
9
|
-
For example, when this field is set in a `tsconfig.json` as so:
|
|
10
|
-
|
|
11
|
-
```jsonc
|
|
12
|
-
{
|
|
13
|
-
"compilerOptions": {
|
|
14
|
-
"target": "es2022",
|
|
15
|
-
"moduleResolution": "bundler",
|
|
16
|
-
"customConditions": ["my-condition"],
|
|
17
|
-
},
|
|
18
|
-
}
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
Any time an `exports` or `imports` field is referenced in `package.json`, TypeScript will consider conditions called `my-condition`.
|
|
22
|
-
|
|
23
|
-
So when importing from a package with the following `package.json`
|
|
24
|
-
|
|
25
|
-
```jsonc
|
|
26
|
-
{
|
|
27
|
-
// ...
|
|
28
|
-
"exports": {
|
|
29
|
-
".": {
|
|
30
|
-
"my-condition": "./foo.mjs",
|
|
31
|
-
"node": "./bar.mjs",
|
|
32
|
-
"import": "./baz.mjs",
|
|
33
|
-
"require": "./biz.mjs",
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
}
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
TypeScript will try to look for files corresponding to `foo.mjs`.
|
|
40
|
-
|
|
41
|
-
This field is only valid under the `node16`, `nodenext`, and `bundler` options for [`--moduleResolution`](#moduleResolution).
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
display: 'Declaration'
|
|
3
|
-
oneline: 'Generate .d.ts files from TypeScript and JavaScript files in your project.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
Generate `.d.ts` files for every TypeScript or JavaScript file inside your project.
|
|
7
|
-
These `.d.ts` files are type definition files which describe the external API of your module.
|
|
8
|
-
With `.d.ts` files, tools like TypeScript can provide intellisense and accurate types for un-typed code.
|
|
9
|
-
|
|
10
|
-
When `declaration` is set to `true`, running the compiler with this TypeScript code:
|
|
11
|
-
|
|
12
|
-
```ts twoslash
|
|
13
|
-
export let helloWorld = 'hi';
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
Will generate an `index.js` file like this:
|
|
17
|
-
|
|
18
|
-
```ts twoslash
|
|
19
|
-
// @showEmit
|
|
20
|
-
export let helloWorld = 'hi';
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
With a corresponding `helloWorld.d.ts`:
|
|
24
|
-
|
|
25
|
-
```ts twoslash
|
|
26
|
-
// @showEmittedFile: index.d.ts
|
|
27
|
-
// @showEmit
|
|
28
|
-
// @declaration
|
|
29
|
-
export let helloWorld = 'hi';
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
When working with `.d.ts` files for JavaScript files you may want to use [`emitDeclarationOnly`](#emitDeclarationOnly) or use [`outDir`](#outDir) to ensure that the JavaScript files are not overwritten.
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
display: 'Declaration Dir'
|
|
3
|
-
oneline: 'Specify the output directory for generated declaration files.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
Offers a way to configure the root directory for where declaration files are emitted.
|
|
7
|
-
|
|
8
|
-
```
|
|
9
|
-
example
|
|
10
|
-
├── index.ts
|
|
11
|
-
├── package.json
|
|
12
|
-
└── tsconfig.json
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
with this `tsconfig.json`:
|
|
16
|
-
|
|
17
|
-
```json tsconfig
|
|
18
|
-
{
|
|
19
|
-
"compilerOptions": {
|
|
20
|
-
"declaration": true,
|
|
21
|
-
"declarationDir": "./types"
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
Would place the d.ts for the `index.ts` in a `types` folder:
|
|
27
|
-
|
|
28
|
-
```
|
|
29
|
-
example
|
|
30
|
-
├── index.js
|
|
31
|
-
├── index.ts
|
|
32
|
-
├── package.json
|
|
33
|
-
├── tsconfig.json
|
|
34
|
-
└── types
|
|
35
|
-
└── index.d.ts
|
|
36
|
-
```
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
display: 'Declaration Map'
|
|
3
|
-
oneline: 'Create sourcemaps for d.ts files.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
Generates a source map for `.d.ts` files which map back to the original `.ts` source file.
|
|
7
|
-
This will allow editors such as VS Code to go to the original `.ts` file when using features like _Go to Definition_.
|
|
8
|
-
|
|
9
|
-
You should strongly consider turning this on if you're using project references.
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
display: 'Diagnostics'
|
|
3
|
-
oneline: 'Output compiler performance information after building.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
Used to output diagnostic information for debugging. This command is a subset of [`extendedDiagnostics`](#extendedDiagnostics) which are more user-facing results, and easier to interpret.
|
|
7
|
-
|
|
8
|
-
If you have been asked by a TypeScript compiler engineer to give the results using this flag in a compile, in which there is no harm in using [`extendedDiagnostics`](#extendedDiagnostics) instead.
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
display: 'Disable Filename Based Type Acquisition'
|
|
3
|
-
oneline: 'Disables inference for type acquisition by looking at filenames in a project.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
TypeScript's type acquisition can infer what types should be added based on filenames in a project. This means that having a file like `jquery.js` in your project would automatically download the types for JQuery from DefinitelyTyped.
|
|
7
|
-
|
|
8
|
-
You can disable this via `disableFilenameBasedTypeAcquisition`.
|
|
9
|
-
|
|
10
|
-
```json
|
|
11
|
-
{
|
|
12
|
-
"typeAcquisition": {
|
|
13
|
-
"disableFilenameBasedTypeAcquisition": true
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
```
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
display: 'Disable Referenced Project Load'
|
|
3
|
-
oneline: 'Reduce the number of projects loaded automatically by TypeScript.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
In multi-project TypeScript programs, TypeScript will load all of the available projects into memory in order to provide accurate results for editor responses which require a full knowledge graph like 'Find All References'.
|
|
7
|
-
|
|
8
|
-
If your project is large, you can use the flag `disableReferencedProjectLoad` to disable the automatic loading of all projects. Instead, projects are loaded dynamically as you open files through your editor.
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
display: 'Disable Size Limit'
|
|
3
|
-
oneline: 'Remove the 20mb cap on total source code size for JavaScript files in the TypeScript language server.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
To avoid a possible memory bloat issues when working with very large JavaScript projects, there is an upper limit to the amount of memory TypeScript will allocate. Turning this flag on will remove the limit.
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
display: 'Disable Solution Searching'
|
|
3
|
-
oneline: 'Opt a project out of multi-project reference checking when editing.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
When working with [composite TypeScript projects](/docs/handbook/project-references.html), this option provides a way to declare that you do not want a project to be included when using features like _find all references_ or _jump to definition_ in an editor.
|
|
7
|
-
|
|
8
|
-
This flag is something you can use to increase responsiveness in large composite projects.
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
display: 'Disable Source Project Reference Redirect'
|
|
3
|
-
oneline: 'Disable preferring source files instead of declaration files when referencing composite projects.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
When working with [composite TypeScript projects](/docs/handbook/project-references.html), this option provides a way to go [back to the pre-3.7](/docs/handbook/release-notes/typescript-3-7.html#build-free-editing-with-project-references) behavior where d.ts files were used to as the boundaries between modules.
|
|
7
|
-
In 3.7 the source of truth is now your TypeScript files.
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
display: 'Downlevel Iteration'
|
|
3
|
-
oneline: 'Emit more compliant, but verbose and less performant JavaScript for iteration.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
Downleveling is TypeScript's term for transpiling to an older version of JavaScript.
|
|
7
|
-
This flag is to enable support for a more accurate implementation of how modern JavaScript iterates through new concepts in older JavaScript runtimes.
|
|
8
|
-
|
|
9
|
-
ECMAScript 6 added several new iteration primitives: the `for / of` loop (`for (el of arr)`), Array spread (`[a, ...b]`), argument spread (`fn(...args)`), and `Symbol.iterator`.
|
|
10
|
-
`downlevelIteration` allows for these iteration primitives to be used more accurately in ES5 environments if a `Symbol.iterator` implementation is present.
|
|
11
|
-
|
|
12
|
-
#### Example: Effects on `for / of`
|
|
13
|
-
|
|
14
|
-
With this TypeScript code:
|
|
15
|
-
|
|
16
|
-
```ts twoslash
|
|
17
|
-
const str = 'Hello!';
|
|
18
|
-
for (const s of str) {
|
|
19
|
-
console.log(s);
|
|
20
|
-
}
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
Without `downlevelIteration` enabled, a `for / of` loop on any object is downleveled to a traditional `for` loop:
|
|
24
|
-
|
|
25
|
-
```ts twoslash
|
|
26
|
-
// @target: ES5
|
|
27
|
-
// @showEmit
|
|
28
|
-
const str = 'Hello!';
|
|
29
|
-
for (const s of str) {
|
|
30
|
-
console.log(s);
|
|
31
|
-
}
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
This is often what people expect, but it's not 100% compliant with ECMAScript iteration protocol.
|
|
35
|
-
Certain strings, such as emoji (😜), have a `.length` of 2 (or even more!), but should iterate as 1 unit in a `for-of` loop.
|
|
36
|
-
See [this blog post by Jonathan New](https://blog.jonnew.com/posts/poo-dot-length-equals-two) for a longer explanation.
|
|
37
|
-
|
|
38
|
-
When `downlevelIteration` is enabled, TypeScript will use a helper function that checks for a `Symbol.iterator` implementation (either native or polyfill).
|
|
39
|
-
If this implementation is missing, you'll fall back to index-based iteration.
|
|
40
|
-
|
|
41
|
-
```ts twoslash
|
|
42
|
-
// @target: ES5
|
|
43
|
-
// @downlevelIteration
|
|
44
|
-
// @showEmit
|
|
45
|
-
const str = 'Hello!';
|
|
46
|
-
for (const s of str) {
|
|
47
|
-
console.log(s);
|
|
48
|
-
}
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
You can use [tslib](https://www.npmjs.com/package/tslib) via [`importHelpers`](#importHelpers) to reduce the amount of inline JavaScript too:
|
|
52
|
-
|
|
53
|
-
```ts twoslash
|
|
54
|
-
// @target: ES5
|
|
55
|
-
// @downlevelIteration
|
|
56
|
-
// @importHelpers
|
|
57
|
-
// @showEmit
|
|
58
|
-
const str = 'Hello!';
|
|
59
|
-
for (const s of str) {
|
|
60
|
-
console.log(s);
|
|
61
|
-
}
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
**Note:** enabling `downlevelIteration` does not improve compliance if `Symbol.iterator` is not present in the runtime.
|
|
65
|
-
|
|
66
|
-
#### Example: Effects on Array Spreads
|
|
67
|
-
|
|
68
|
-
This is an array spread:
|
|
69
|
-
|
|
70
|
-
```js
|
|
71
|
-
// Make a new array whose elements are 1 followed by the elements of arr2
|
|
72
|
-
const arr = [1, ...arr2];
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
Based on the description, it sounds easy to downlevel to ES5:
|
|
76
|
-
|
|
77
|
-
```js
|
|
78
|
-
// The same, right?
|
|
79
|
-
const arr = [1].concat(arr2);
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
However, this is observably different in certain rare cases.
|
|
83
|
-
|
|
84
|
-
For example, if a source array is missing one or more items (contains a hole), the spread syntax will replace each empty item with `undefined`, whereas `.concat` will leave them intact.
|
|
85
|
-
|
|
86
|
-
```js
|
|
87
|
-
// Make an array where the element at index 1 is missing
|
|
88
|
-
let arrayWithHole = ['a', , 'c'];
|
|
89
|
-
let spread = [...arrayWithHole];
|
|
90
|
-
let concatenated = [].concat(arrayWithHole);
|
|
91
|
-
|
|
92
|
-
console.log(arrayWithHole);
|
|
93
|
-
// [ 'a', <1 empty item>, 'c' ]
|
|
94
|
-
console.log(spread);
|
|
95
|
-
// [ 'a', undefined, 'c' ]
|
|
96
|
-
console.log(concatenated);
|
|
97
|
-
// [ 'a', <1 empty item>, 'c' ]
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
Just as with `for / of`, `downlevelIteration` will use `Symbol.iterator` (if present) to more accurately emulate ES 6 behavior.
|
package/docs/tsconfig/emitBOM.md
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
display: 'Emit BOM'
|
|
3
|
-
oneline: 'Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
Controls whether TypeScript will emit a [byte order mark (BOM)](https://wikipedia.org/wiki/Byte_order_mark) when writing output files.
|
|
7
|
-
Some runtime environments require a BOM to correctly interpret a JavaScript files; others require that it is not present.
|
|
8
|
-
The default value of `false` is generally best unless you have a reason to change it.
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
display: 'Emit Declaration Only'
|
|
3
|
-
oneline: 'Only output d.ts files and not JavaScript files.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
_Only_ emit `.d.ts` files; do not emit `.js` files.
|
|
7
|
-
|
|
8
|
-
This setting is useful in two cases:
|
|
9
|
-
|
|
10
|
-
- You are using a transpiler other than TypeScript to generate your JavaScript.
|
|
11
|
-
- You are using TypeScript to only generate `d.ts` files for your consumers.
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
display: 'Emit Decorator Metadata'
|
|
3
|
-
oneline: 'Emit design-type metadata for decorated declarations in source files.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
Enables experimental support for emitting type metadata for decorators which works with the module [`reflect-metadata`](https://www.npmjs.com/package/reflect-metadata).
|
|
7
|
-
|
|
8
|
-
For example, here is the TypeScript
|
|
9
|
-
|
|
10
|
-
```ts twoslash
|
|
11
|
-
// @experimentalDecorators
|
|
12
|
-
function LogMethod(
|
|
13
|
-
target: any,
|
|
14
|
-
propertyKey: string | symbol,
|
|
15
|
-
descriptor: PropertyDescriptor,
|
|
16
|
-
) {
|
|
17
|
-
console.log(target);
|
|
18
|
-
console.log(propertyKey);
|
|
19
|
-
console.log(descriptor);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
class Demo {
|
|
23
|
-
@LogMethod
|
|
24
|
-
public foo(bar: number) {
|
|
25
|
-
// do nothing
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const demo = new Demo();
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
With `emitDecoratorMetadata` not set to true (default) the emitted JavaScript is:
|
|
33
|
-
|
|
34
|
-
```ts twoslash
|
|
35
|
-
// @experimentalDecorators
|
|
36
|
-
// @showEmit
|
|
37
|
-
function LogMethod(
|
|
38
|
-
target: any,
|
|
39
|
-
propertyKey: string | symbol,
|
|
40
|
-
descriptor: PropertyDescriptor,
|
|
41
|
-
) {
|
|
42
|
-
console.log(target);
|
|
43
|
-
console.log(propertyKey);
|
|
44
|
-
console.log(descriptor);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
class Demo {
|
|
48
|
-
@LogMethod
|
|
49
|
-
public foo(bar: number) {
|
|
50
|
-
// do nothing
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const demo = new Demo();
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
With `emitDecoratorMetadata` set to true the emitted JavaScript is:
|
|
58
|
-
|
|
59
|
-
```ts twoslash
|
|
60
|
-
// @experimentalDecorators
|
|
61
|
-
// @showEmit
|
|
62
|
-
// @emitDecoratorMetadata
|
|
63
|
-
function LogMethod(
|
|
64
|
-
target: any,
|
|
65
|
-
propertyKey: string | symbol,
|
|
66
|
-
descriptor: PropertyDescriptor,
|
|
67
|
-
) {
|
|
68
|
-
console.log(target);
|
|
69
|
-
console.log(propertyKey);
|
|
70
|
-
console.log(descriptor);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
class Demo {
|
|
74
|
-
@LogMethod
|
|
75
|
-
public foo(bar: number) {
|
|
76
|
-
// do nothing
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const demo = new Demo();
|
|
81
|
-
```
|
package/docs/tsconfig/enable.md
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
display: 'Erasable Syntax Only'
|
|
3
|
-
oneline: 'Do not allow runtime constructs that are not part of ECMAScript.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
Node.js [supports running TypeScript files directly](https://nodejs.org/api/typescript.html#type-stripping) as of v23.6;
|
|
7
|
-
however, only TypeScript-specific syntax that does not have runtime semantics are supported under this mode.
|
|
8
|
-
In other words, it must be possible to easily _erase_ any TypeScript-specific syntax from a file, leaving behind a valid JavaScript file.
|
|
9
|
-
|
|
10
|
-
That means the following constructs are not supported:
|
|
11
|
-
|
|
12
|
-
- `enum` declarations
|
|
13
|
-
- `namespace`s and `module`s with runtime code
|
|
14
|
-
- parameter properties in classes
|
|
15
|
-
- Non-ECMAScript `import =` and `export =` assignments
|
|
16
|
-
|
|
17
|
-
```ts
|
|
18
|
-
// ❌ error: An `import ... = require(...)` alias
|
|
19
|
-
import foo = require('foo');
|
|
20
|
-
|
|
21
|
-
// ❌ error: A namespace with runtime code.
|
|
22
|
-
namespace container {
|
|
23
|
-
foo.method();
|
|
24
|
-
|
|
25
|
-
export type Bar = string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// ❌ error: An `import =` alias
|
|
29
|
-
import Bar = container.Bar;
|
|
30
|
-
|
|
31
|
-
class Point {
|
|
32
|
-
// ❌ error: Parameter properties
|
|
33
|
-
constructor(
|
|
34
|
-
public x: number,
|
|
35
|
-
public y: number,
|
|
36
|
-
) {}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// ❌ error: An `export =` assignment.
|
|
40
|
-
export = Point;
|
|
41
|
-
|
|
42
|
-
// ❌ error: An enum declaration.
|
|
43
|
-
enum Direction {
|
|
44
|
-
Up,
|
|
45
|
-
Down,
|
|
46
|
-
Left,
|
|
47
|
-
Right,
|
|
48
|
-
}
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
Similar tools like [ts-blank-space](https://github.com/bloomberg/ts-blank-space) or [Amaro](https://github.com/nodejs/amaro) (the underlying library for type-stripping in Node.js) have the same limitations.
|
|
52
|
-
These tools will provide helpful error messages if they encounter code that doesn't meet these requirements, but you still won't find out your code doesn't work until you actually try to run it.
|
|
53
|
-
|
|
54
|
-
The `--erasableSyntaxOnly` flag will cause TypeScript to error on most TypeScript-specific constructs that have runtime behavior.
|
|
55
|
-
|
|
56
|
-
```ts
|
|
57
|
-
class C {
|
|
58
|
-
constructor(public x: number) { }
|
|
59
|
-
// ~~~~~~~~~~~~~~~~
|
|
60
|
-
// error! This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
Typically, you will want to combine this flag with the `--verbatimModuleSyntax`, which ensures that a module contains the appropriate import syntax, and that import elision does not take place.
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
display: 'ES Module Interop'
|
|
3
|
-
oneline: 'Emit additional JavaScript to ease support for importing CommonJS modules. This enables [`allowSyntheticDefaultImports`](#allowSyntheticDefaultImports) for type compatibility.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
By default (with `esModuleInterop` false or not set) TypeScript treats CommonJS/AMD/UMD modules similar to ES6 modules. In doing this, there are two parts in particular which turned out to be flawed assumptions:
|
|
7
|
-
|
|
8
|
-
- a namespace import like `import * as moment from "moment"` acts the same as `const moment = require("moment")`
|
|
9
|
-
|
|
10
|
-
- a default import like `import moment from "moment"` acts the same as `const moment = require("moment").default`
|
|
11
|
-
|
|
12
|
-
This mis-match causes these two issues:
|
|
13
|
-
|
|
14
|
-
- the ES6 modules spec states that a namespace import (`import * as x`) can only be an object, by having TypeScript
|
|
15
|
-
treating it the same as `= require("x")` then TypeScript allowed for the import to be treated as a function and be callable. That's not valid according to the spec.
|
|
16
|
-
|
|
17
|
-
- while accurate to the ES6 modules spec, most libraries with CommonJS/AMD/UMD modules didn't conform as strictly as TypeScript's implementation.
|
|
18
|
-
|
|
19
|
-
Turning on `esModuleInterop` will fix both of these problems in the code transpiled by TypeScript. The first changes the behavior in the compiler, the second is fixed by two new helper functions which provide a shim to ensure compatibility in the emitted JavaScript:
|
|
20
|
-
|
|
21
|
-
```ts
|
|
22
|
-
import * as fs from 'fs';
|
|
23
|
-
import _ from 'lodash';
|
|
24
|
-
|
|
25
|
-
fs.readFileSync('file.txt', 'utf8');
|
|
26
|
-
_.chunk(['a', 'b', 'c', 'd'], 2);
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
With `esModuleInterop` disabled:
|
|
30
|
-
|
|
31
|
-
```ts twoslash
|
|
32
|
-
// @noErrors
|
|
33
|
-
// @showEmit
|
|
34
|
-
// @esModuleInterop: false
|
|
35
|
-
// @module: commonjs
|
|
36
|
-
import * as fs from 'fs';
|
|
37
|
-
import _ from 'lodash';
|
|
38
|
-
|
|
39
|
-
fs.readFileSync('file.txt', 'utf8');
|
|
40
|
-
_.chunk(['a', 'b', 'c', 'd'], 2);
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
With `esModuleInterop` set to `true`:
|
|
44
|
-
|
|
45
|
-
```ts twoslash
|
|
46
|
-
// @noErrors
|
|
47
|
-
// @showEmit
|
|
48
|
-
// @esModuleInterop
|
|
49
|
-
// @module: commonjs
|
|
50
|
-
import * as fs from 'fs';
|
|
51
|
-
import _ from 'lodash';
|
|
52
|
-
|
|
53
|
-
fs.readFileSync('file.txt', 'utf8');
|
|
54
|
-
_.chunk(['a', 'b', 'c', 'd'], 2);
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
_Note_: The namespace import `import * as fs from "fs"` only accounts for properties which [are owned](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty) (basically properties set on the object and not via the prototype chain) on the imported object. If the module you're importing defines its API using inherited properties, you need to use the default import form (`import fs from "fs"`), or disable `esModuleInterop`.
|
|
58
|
-
|
|
59
|
-
_Note_: You can make JS emit terser by enabling [`importHelpers`](#importHelpers):
|
|
60
|
-
|
|
61
|
-
```ts twoslash
|
|
62
|
-
// @noErrors
|
|
63
|
-
// @showEmit
|
|
64
|
-
// @esModuleInterop
|
|
65
|
-
// @importHelpers
|
|
66
|
-
// @module: commonjs
|
|
67
|
-
import * as fs from 'fs';
|
|
68
|
-
import _ from 'lodash';
|
|
69
|
-
|
|
70
|
-
fs.readFileSync('file.txt', 'utf8');
|
|
71
|
-
_.chunk(['a', 'b', 'c', 'd'], 2);
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
Enabling `esModuleInterop` will also enable [`allowSyntheticDefaultImports`](#allowSyntheticDefaultImports).
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
display: 'Exact Optional Property Types'
|
|
3
|
-
oneline: 'Interpret optional property types as written, rather than adding `undefined`.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
With exactOptionalPropertyTypes enabled, TypeScript applies stricter rules around how it handles properties on `type` or `interfaces` which have a `?` prefix.
|
|
7
|
-
|
|
8
|
-
For example, this interface declares that there is a property which can be one of two strings: 'dark' or 'light' or it should not be in the object.
|
|
9
|
-
|
|
10
|
-
```ts
|
|
11
|
-
interface UserDefaults {
|
|
12
|
-
// The absence of a value represents 'system'
|
|
13
|
-
colorThemeOverride?: 'dark' | 'light';
|
|
14
|
-
}
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
Without this flag enabled, there are three values which you can set `colorThemeOverride` to be: "dark", "light" and `undefined`.
|
|
18
|
-
|
|
19
|
-
Setting the value to `undefined` will allow most JavaScript runtime checks for the existence to fail, which is effectively falsy. However, this isn't quite accurate; `colorThemeOverride: undefined` is not the same as `colorThemeOverride` not being defined. For example, `"colorThemeOverride" in settings` would have different behavior with `undefined` as the key compared to not being defined.
|
|
20
|
-
|
|
21
|
-
`exactOptionalPropertyTypes` makes TypeScript truly enforce the definition provided as an optional property:
|
|
22
|
-
|
|
23
|
-
```ts twoslash
|
|
24
|
-
// @exactOptionalPropertyTypes
|
|
25
|
-
// @errors: 2322 2412
|
|
26
|
-
interface UserDefaults {
|
|
27
|
-
colorThemeOverride?: 'dark' | 'light';
|
|
28
|
-
}
|
|
29
|
-
declare function getUserSettings(): UserDefaults;
|
|
30
|
-
// ---cut---
|
|
31
|
-
const settings = getUserSettings();
|
|
32
|
-
settings.colorThemeOverride = 'dark';
|
|
33
|
-
settings.colorThemeOverride = 'light';
|
|
34
|
-
|
|
35
|
-
// But not:
|
|
36
|
-
settings.colorThemeOverride = undefined;
|
|
37
|
-
```
|
package/docs/tsconfig/exclude.md
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
display: 'Exclude'
|
|
3
|
-
oneline: 'Filters results from the [`include`](#include) option.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
Specifies an array of filenames or patterns that should be skipped when resolving [`include`](#include).
|
|
7
|
-
|
|
8
|
-
**Important**: `exclude` _only_ changes which files are included as a result of the [`include`](#include) setting.
|
|
9
|
-
A file specified by `exclude` can still become part of your codebase due to an `import` statement in your code, a `types` inclusion, a `/// <reference` directive, or being specified in the [`files`](#files) list.
|
|
10
|
-
|
|
11
|
-
It is not a mechanism that **prevents** a file from being included in the codebase - it simply changes what the [`include`](#include) setting finds.
|