ts config 配置说明

1,生成配置文件

1
tsc --init

2,配置文件说明 – tsconfig.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
{
"compilerOptions": {
/* Basic Options */
"target": "es5", /*用于指定编译后的目标版本 Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */

"module": "commonjs", /*用来指定要使用的目标版本 Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
// "lib": [], /*用于指定要包含在编译中的库文件,比如es6,dom Specify library files to be included in the compilation. */

// "allowJs": true, /*用来指定是否编译js文件,默认为false,不编译 Allow javascript files to be compiled. */

// "checkJs": true, /*用来指定是否检测和报告js中的错误,默认为false Report errors in .js files. */

// "jsx": "preserve", /*指定jsx代码用于的开发环境 Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /*用来指定是否在编译的时候生成声明文件.d.ts,但declaration 和allowjs 不能同时设置为true。 Generates corresponding '.d.ts' file. */
// "declarationMap": true, /*用来指定是否为声明文件.d.ts 生成map文件 Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /*用来指定编译时是否生成map文件 Generates corresponding '.map' file. */
// "outFile": "./", /*用来指定将输出文件合并为一个文件,比如设置为"./dist/main.js",则输出的文件为一个main.js文件,但要注意的是只有设置module的值为amd和system模块时才支持这个配置 Concatenate and emit output to single file. */
// "outDir": "./", /*用来指定输出文件存放的文件夹路径 Redirect output structure to the directory. */
// "rootDir": "./", /*用来指定编译文件的根目录,编译器会在根目录查找入口文件,如果编译器发现以rootDir的值作为根目录查找入口文件并不会把所有文件加载进去的话会报错,但不会停止项目编译。 Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /*是否编译构建引用项目。 Enable project compilation */
// "removeComments": true, /*是否在编译后的文件中把注释删掉 Do not emit comments to output. */
// "noEmit": true, /*不生成编译文件,这个一般很少用 Do not emit outputs. */
// "importHelpers": true, /*指定是否引入tslib里面的辅助工具函数,默认为false Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /*当target为"es5"或"es3"时,为迭代器"for-of"等提供完全支持, Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /*指定是否将每个文件作为单独的模块,默认为true,他不能和declaration同时设定 Transpile each file as a separate module (similar to 'ts.transpileModule'). */

/* Strict Type-Checking Options */
"strict": true, /*如果设置为true,则开启所有的严格性检查 Enable all strict type-checking options. */
// "noImplicitAny": true, /*如果设置为false,当我们没有明确指定类型时,编译器默认这个值为any类型,如果设置为true,则没有设置明确的类型就会报错,默认为false Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /*如果设置为true,null和undefined值不能赋值给非这两种类型的值,别的类型的值也不能赋给他们,除了any类型,还有个例外就是undefined可以赋值给void类型。 Enable strict null checks. */
// "strictFunctionTypes": true, /*用来指定是否使用函数参数双向协变。 Enable strict checking of function types. */
// "strictBindCallApply": true, /*是否对bind,call和apply绑定的方法的参数严格检查 Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /*设置为true会检查类的非undefined属性是否已经在构建函数里面初始化,如果开启也需要设置strictNullChecks 也为true, 默认为false。 Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /*当this的值为any类型,会报错 Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /*指定始终以严格的模式检查每个模块,并且在生成的js文件中会包含"use strict" Parse in strict mode and emit "use strict" for each source file. */

/* Additional Checks */
// "noUnusedLocals": true, /*是否检查有定义但没有使用的变量,对于这一点的检查,使用eslint 可以在你书写的时候做提示,可以配合使用,默认为false。 Report errors on unused locals. */
// "noUnusedParameters": true, /*检查函数中是否有定义的参数没有用,也可以配合eslint Report errors on unused parameters. */
// "noImplicitReturns": true, /*检查函数是否有返回值,没有的话就会报错, Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /*检查switch语句中case是否用break跳出 Report errors for fallthrough cases in switch statement. */

/* Module Resolution Options */
// "moduleResolution": "node", /*用于选择模块解析测量。 Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /*用户设置解析非相对模块名称的根目录,相对模块不受影响。 Base directory to resolve non-absolute module names. */
// "paths": {
// "*": ["node_modules/@types", "src/typings"]
//}, /*用于设定模块名基于baseUrl的路径映射. A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /*可以指定一个路径列表,在构建时编译器会将这个路径列表中的路径中的内容都放在一个文件中。 List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /*用来指定声明文件或文件夹的路径列表,如果指定了此项,,则只有这里列出的声明文件才会被加载。 List of folders to include type definitions from. */
// "types": [], /*用来指定需要包含的模块,只有在这里列出来的模块的声明文件才会被加载进来。 Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /*用来指定允许从没有默认导出的模块中导入。 Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /*通过为导入内容创建命名空间,实现CommonJs和ES模块之间的互操作性。 Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /*不把符号链接解析为真实路径,具体可以参考webpack和nodejs的symlink相关知识 Do not resolve the real path of symlinks. */

/* Source Map Options */
// "sourceRoot": "", /*用于指定调试器应该找到Typescrit文件而不是源文件,这个值会被写进.map文件。 Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /*用于指定调试器找到映射文件而非生成文件到位置,指定map文件的根路径,该选项会影响.map文件中的sources属性。 Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /*是否将map文件中的内容和js文件编译在同一个文件中。 Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /*是否进一步将ts文件的内容也包含到输出文件中。 Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

/* Experimental Options */
// "experimentalDecorators": true, /*用于指定是否启用实验性的装饰器特性。 Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /*用于指定是否为装饰器提供元数据支持,关于元数据,也是ES6的新标准,可以通过Reflect提供的静态方法获取元数据,如果需要使用Reflect的一些方法,需要引入ES2015.Reflect这个库。 Enables experimental support for emitting type metadata for decorators. */
},
// "files":[], /*fils 可以配置一个数组列表,里面包含指定文件的相对或绝对路径,编译器在编译的时候,只会编译包含砸files中列出的文件。如果不指定,则取决于有没有设置include选项,如果没有include选项,则默认惠编译根目录以及所有子目录中的文件。这里列出的路径必须是指定文件,而不是某个文件夹,并且不能使用通配符,比如 * ? */
// "include":[],/* include 也可以指定要编译的路径列表,但和files的区别在于,这里的路径可以是文件或文件夹,可以使用相对或绝对路径,可以使用通配符, 例如,"./src"即表示要编译的src文件下的所有文件以及子文件夹的文件*/
// "exclude":[], /*规则和include 是一样的,这里表示的是要排除编译的文件或文件夹 */
// "extends":"", /* extends 可以指定一个其他的tsconfig.json文件路径,来继承这个配置文件里的配置,继承来的文件的配置惠覆盖当前文件的配置*/
// "compileOnSave":true, /*如果设置为true,我们在编辑了项目文件保存的时候,编译器会根据tsconfig.json的配置重新生成文件,不过这个需要编译器支持*/
// references: [], // 指定要引用的项目,
}