Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 7f18053

Browse files
authored
Merge pull request #438 from Microsoft/compilerOptions2.1
Update compiler options for TS 2.1
2 parents d9d1675 + 7b2ca4e commit 7f18053

File tree

2 files changed

+67
-14
lines changed

2 files changed

+67
-14
lines changed

pages/Compiler Options.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,43 @@ Option | Type | Default
66
`--allowSyntheticDefaultImports` | `boolean` | `module === "system"` | Allow default imports from modules with no default export. This does not affect code emit, just typechecking.
77
`--allowUnreachableCode` | `boolean` | `false` | Do not report errors on unreachable code.
88
`--allowUnusedLabels` | `boolean` | `false` | Do not report errors on unused labels.
9+
`--alwaysStrict` | `boolean` | `false` | Parse in strict mode and emit `"use strict"` for each source file
910
`--baseUrl` | `string` | | Base directory to resolve non-relative module names. See [Module Resolution documentation](./Module Resolution.md#base-url) for more details.
1011
`--charset` | `string` | `"utf8"` | The character set of the input files.
11-
`--declaration`<br/>`-d` | `boolean` | `false` | Generates corresponding '.d.ts' file.
12+
`--declaration`<br/>`-d` | `boolean` | `false` | Generates corresponding `.d.ts` file.
1213
`--declarationDir` | `string` | | Output directory for generated declaration files.
1314
`--diagnostics` | `boolean` | `false` | Show diagnostic information.
1415
`--disableSizeLimit` | `boolean` | `false` | Disable size limitation on JavaScript project.
1516
`--emitBOM` | `boolean` | `false` | Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files.
1617
`--emitDecoratorMetadata`<sup>[1]</sup> | `boolean` | `false` | Emit design-type metadata for decorated declarations in source. See [issue #2577](https://github.com/Microsoft/TypeScript/issues/2577) for details.
17-
`--experimentalDecorators`<sup>[1]</sup> | `boolean` | `false` | Enables experimental support for ES7 decorators.
18+
`--experimentalDecorators`<sup>[1]</sup> | `boolean` | `false` | Enables experimental support for ES decorators.
1819
`--forceConsistentCasingInFileNames` | `boolean` | `false` | Disallow inconsistently-cased references to the same file.
1920
`--help`<br/>`-h` | | | Print help message.
21+
`--importHelpers` | `string` | | Import emit helpers (e.g. `__extends`, `__rest`, etc..) from [`tslib`](https://www.npmjs.com/package/tslib)
2022
`--inlineSourceMap` | `boolean` | `false` | Emit a single file with source maps instead of having a separate file.
2123
`--inlineSources` | `boolean` | `false` | Emit the source alongside the sourcemaps within a single file; requires `--inlineSourceMap` or `--sourceMap` to be set.
2224
`--init` | | | Initializes a TypeScript project and creates a `tsconfig.json` file.
2325
`--isolatedModules` | `boolean` | `false` | Unconditionally emit imports for unresolved files.
24-
`--jsx` | `string` | `"Preserve"` | Support JSX in '.tsx' files: `'React'` or `'Preserve'`. See [JSX](./JSX.md).
25-
`--lib` | `string[]`| | List of library files to be included in the compilation.<br/>Possible values are: <br/>► `es5` <br/>► `es6` <br/>► `es2015` <br/>► `es7` <br/>► `es2016` <br/>► `es2017` <br/>► `dom` <br/>► `webworker` <br/>► `scripthost` <br/>► `es2015.core` <br/>► `es2015.collection` <br/>► `es2015.generator` <br/>► `es2015.iterable` <br/>► `es2015.promise` <br/>► `es2015.proxy` <br/>► `es2015.reflect` <br/>► `es2015.symbol` <br/>► `es2015.symbol.wellknown` <br/>► `es2016.array.include` <br/>► `es2017.object` <br/>► `es2017.sharedmemory` <br/><br/> Note: If `--lib` is not specified a default library is injected. The default library injected is: <br/> ► For `--target ES5`: `dom,es5,scripthost`<br/> ► For `--target ES6`: `dom,es6,dom.iterable,scripthost`
26+
`--jsx` | `string` | `"Preserve"` | Support JSX in `.tsx` files: `"React"` or `"Preserve"`. See [JSX](./JSX.md).
27+
`--jsxFactory` | `string` | `"React.createElement"` | Specify the JSX factory function to use when targeting react JSX emit, e.g. `React.createElement` or `h`.
28+
`--lib` | `string[]`| | List of library files to be included in the compilation.<br/>Possible values are: <br/>► `ES5` <br/>► `ES6` <br/>► `ES2015` <br/>► `ES7` <br/>► `ES2016` <br/>► `ES2017` <br/>► `DOM` <br/>► `DOM.Iterable` <br/>► `WebWorker` <br/>► `ScriptHost` <br/>► `ES2015.Core` <br/>► `ES2015.Collection` <br/>► `ES2015.Generator` <br/>► `ES2015.Iterable` <br/>► `ES2015.Promise` <br/>► `ES2015.Proxy` <br/>► `ES2015.Reflect` <br/>► `ES2015.Symbol` <br/>► `ES2015.Symbol.WellKnown` <br/>► `ES2016.Array.Include` <br/>► `ES2017.object` <br/>► `ES2017.SharedMemory` <br/><br/> Note: If `--lib` is not specified a default library is injected. The default library injected is: <br/> ► For `--target ES5`: `DOM,ES5,ScriptHost`<br/> ► For `--target ES6`: `DOM,ES6,DOM.Iterable,ScriptHost`
2629
`--listEmittedFiles` | `boolean` | `false` | Print names of generated files part of the compilation.
2730
`--listFiles` | `boolean` | `false` | Print names of files part of the compilation.
2831
`--locale` | `string` | *(platform specific)* | The locale to use to show error messages, e.g. en-us.
2932
`--mapRoot` | `string` | | Specifies the location where debugger should locate map files instead of generated locations. Use this flag if the .map files will be located at run-time in a different location than the .js files. The location specified will be embedded in the sourceMap to direct the debugger where the map files will be located.
3033
`--maxNodeModuleJsDepth` | `number` | `0` | The maximum dependency depth to search under node_modules and load JavaScript files. Only applicable with `--allowJs`.
31-
`--module`<br/>`-m` | `string` | `target === 'ES6' ? 'ES6' : 'commonjs'` | Specify module code generation: `'none'`, `'commonjs'`, `'amd'`, `'system'`, `'umd'`, `'es6'`, or `'es2015'`.<br/>► Only `'amd'` and `'system'` can be used in conjunction with `--outFile`.<br/>► `'es6'` and `'es2015'` values may not be used when targeting ES5 or lower.
32-
`--moduleResolution` | `string` | `module === 'amd' | 'system' | 'ES6' ? 'classic' : 'node'` | Determine how modules get resolved. Either `'node'` for Node.js/io.js style resolution, or `'classic'`. See [Module Resolution documentation](./Module Resolution.md) for more details.
33-
`--newLine` | `string` | *(platform specific)* | Use the specified end of line sequence to be used when emitting files: `'crlf'` (windows) or `'lf'` (unix)."
34+
`--module`<br/>`-m` | `string` | `target === "ES6" ? "ES6" : "CommonJS"` | Specify module code generation: `"None"`, `"CommonJS"`, `"AMD"`, `"System"`, `"UMD"`, `"ES6"`, or `"ES2015"`.<br/>► Only `"AMD"` and `"System"` can be used in conjunction with `--outFile`.<br/>► `"ES6"` and `"ES2015"` values may not be used when targeting `"ES5"` or lower.
35+
`--moduleResolution` | `string` | `module === "AMD" | "System" | "ES6" ? "Classic" : "Node"` | Determine how modules get resolved. Either `"Node"` for Node.js/io.js style resolution, or `"Classic"`. See [Module Resolution documentation](./Module Resolution.md) for more details.
36+
`--newLine` | `string` | *(platform specific)* | Use the specified end of line sequence to be used when emitting files: `"crlf"` (windows) or `"lf"` (unix)."
3437
`--noEmit` | `boolean` | `false` | Do not emit outputs.
3538
`--noEmitHelpers` | `boolean` | `false` | Do not generate custom helper functions like `__extends` in compiled output.
3639
`--noEmitOnError` | `boolean` | `false` | Do not emit outputs if any errors were reported.
3740
`--noFallthroughCasesInSwitch` | `boolean` | `false` | Report errors for fallthrough cases in switch statement.
38-
`--noImplicitAny` | `boolean` | `false` | Raise error on expressions and declarations with an implied 'any' type.
41+
`--noImplicitAny` | `boolean` | `false` | Raise error on expressions and declarations with an implied `any` type.
3942
`--noImplicitReturns` | `boolean` | `false` | Report error when not all code paths in function return a value.
40-
`--noImplicitThis` | `boolean` | `false` | Raise error on `this` expressions with an implied 'any' type.
43+
`--noImplicitThis` | `boolean` | `false` | Raise error on `this` expressions with an implied `any` type.
4144
`--noImplicitUseStrict` | `boolean` | `false` | Do not emit `"use strict"` directives in module output.
42-
`--noLib` | `boolean` | `false` | Do not include the default library file (lib.d.ts).
45+
`--noLib` | `boolean` | `false` | Do not include the default library file (`lib.d.ts`).
4346
`--noResolve` | `boolean` | `false` | Do not add triple-slash references or module import targets to the list of compiled files.
4447
`--noUnusedLocals` | `boolean` | `false` | Report errors on unused locals.
4548
`--noUnusedParameters` | `boolean` | `false` | Report errors on unused parameters.
@@ -50,19 +53,19 @@ Option | Type | Default
5053
`--preserveConstEnums` | `boolean` | `false` | Do not erase const enum declarations in generated code. See [const enums documentation](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#94-constant-enum-declarations) for more details.
5154
`--pretty`<sup>[1]</sup> | `boolean` | `false` | Stylize errors and messages using color and context.
5255
`--project`<br/>`-p` | `string` | | Compile a project given a valid configuration file.<br/>The argument can be an file path to a valid JSON configuration file, or a directory path to a directory containing a `tsconfig.json` file.<br/>See [tsconfig.json](./tsconfig.json.md) documentation for more details.
53-
`--reactNamespace` | `string` | `"React"` | Specifies the object invoked for `createElement` and `__spread` when targeting 'react' JSX emit.
56+
`--reactNamespace` | `string` | `"React"` | Specifies the object invoked for `createElement` and `__spread` when targeting `"react"` JSX emit.
5457
`--removeComments` | `boolean` | `false` | Remove all comments except copy-right header comments beginning with `/*!`
5558
`--rootDir` | `string` | *(common root directory is computed from the list of input files)* | Specifies the root directory of input files. Only use to control the output directory structure with `--outDir`.
5659
`rootDirs`<sup>[2]</sup> | `string[]`| | List of <i>root</i> folders whose combined content represent the structure of the project at runtime. See [Module Resolution documentation](./Module Resolution.md#virtual-directories-with-rootdirs) for more details.
5760
`--skipDefaultLibCheck` | `boolean` | `false` | Skip type checking of [default library declaration files](./Triple-Slash Directives.md#-reference-no-default-libtrue).
5861
`--skipLibCheck` | `boolean` | `false` | Skip type checking of all declaration files (`*.d.ts`).
59-
`--sourceMap` | `boolean` | `false` | Generates corresponding '.map' file.
62+
`--sourceMap` | `boolean` | `false` | Generates corresponding `.map` file.
6063
`--sourceRoot` | `string` | | Specifies the location where debugger should locate TypeScript files instead of source locations. Use this flag if the sources will be located at run-time in a different location than that at design-time. The location specified will be embedded in the sourceMap to direct the debugger where the source files will be located.
6164
`--strictNullChecks` | `boolean` | `false` | In strict null checking mode, the `null` and `undefined` values are not in the domain of every type and are only assignable to themselves and `any` (the one exception being that `undefined` is also assignable to `void`).
6265
`--stripInternal`<sup>[1]</sup> | `boolean` | `false` | Do not emit declarations for code that has an `/** @internal */` JSDoc annotation.
6366
`--suppressExcessPropertyErrors` | `boolean` | `false` | Suppress excess property checks for object literals.
6467
`--suppressImplicitAnyIndexErrors` | `boolean` | `false` | Suppress `--noImplicitAny` errors for indexing objects lacking index signatures. See [issue #1232](https://github.com/Microsoft/TypeScript/issues/1232#issuecomment-64510362) for more details.
65-
`--target`<br/>`-t` | `string` | `"ES3"` | Specify ECMAScript target version: `'es3'` (default), `'es5'`, or `'es6'`.
68+
`--target`<br/>`-t` | `string` | `"ES3"` | Specify ECMAScript target version: `"ES3"` (default), `"ES5"`, `"ES6"`/`"ES2015"`, `"ES2016"`, `"ES2017"` or `"ESNext"`. <br/><br/> Note: `"ESNext"` targets latest supported [ES proposed features](https://github.com/tc39/proposals).
6669
`--traceResolution` | `boolean` | `false` | Report module resolution log messages.
6770
`--types` | `string[]`| | List of names of type definitions to include. See [@types, --typeRoots and --types](./tsconfig.json.md#types-typeroots-and-types) for more details.
6871
`--typeRoots` | `string[]`| | List of folders to include type definitions from. See [@types, --typeRoots and --types](./tsconfig.json.md#types-typeroots-and-types) for more details.

pages/tsconfig.json.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Files in the directory specified using the `"outDir"` compiler option are always
8686

8787
Files included using `"include"` can be filtered using the `"exclude"` property.
8888
However, files included explicitly using the `"files"` property are always included regardless of `"exclude"`.
89-
The `"exclude"` property defaults to excluding the `node_modules`, `bower_components`, and `jspm_packages` directories when not specified.
89+
The `"exclude"` property defaults to excluding the `node_modules`, `bower_components`, `jspm_packages` and `<outDir>` directories when not specified.
9090

9191
Any files that are referenced by files included via the `"files"` or `"include"` properties are also included.
9292
Similarly, if a file `B.ts` is referenced by another file `A.ts`, then `B.ts` cannot be excluded unless the referencing file `A.ts` is also specified in the `"exclude"` list.
@@ -133,6 +133,56 @@ Specify `"types": []` to disable automatic inclusion of `@types` packages.
133133
Keep in mind that automatic inclusion is only important if you're using files with global declarations (as opposed to files declared as modules).
134134
If you use an `import "foo"` statement, for instance, TypeScript may still look through `node_modules` & `node_modules/@types` folders to find the `foo` package.
135135

136+
## Configuration inheritance with `extends`
137+
138+
A `tsconfig.json` file can inherit configurations from another file using the `extends` property.
139+
140+
The `extends` is a top-level property in `tsconfig.json` (alongside `compilerOptions`, `files`, `include`, and `exclude`).
141+
`extends`' value is a string containing a path to another configuration file to inherit from.
142+
143+
The configuration from the base file are loaded first, then overridden by those in the inheriting config file.
144+
If a circularity is encountered, we report an error.
145+
146+
`files`, `include` and `exclude` from the inheriting config file *overwrite* those from the base config file.
147+
148+
All relative paths found in the configuration file will be resolved relative to the configuration file they originated in.
149+
150+
For example:
151+
152+
`configs/base.json`:
153+
154+
```json
155+
{
156+
"compilerOptions": {
157+
"noImplicitAny": true,
158+
"strictNullChecks": true
159+
}
160+
}
161+
```
162+
163+
`tsconfig.json`:
164+
165+
```json
166+
{
167+
"extends": "./configs/base",
168+
"files": [
169+
"main.ts",
170+
"supplemental.ts"
171+
]
172+
}
173+
```
174+
175+
`tsconfig.nostrictnull.json`:
176+
177+
```json
178+
{
179+
"extends": "./tsconfig",
180+
"compilerOptions": {
181+
"strictNullChecks": false
182+
}
183+
}
184+
```
185+
136186
## `compileOnSave`
137187

138188
Setting a top-level property `compileOnSave` signals to the IDE to generate all files for a given tsconfig.json upon saving.

0 commit comments

Comments
 (0)