Typescript中tsconfig.json配置速查

tsconfig.json属性配置,定义typescript将以什么样的方式去编译代码,熟悉常用配置选项,对日常开发将会有一定帮助,即使忘记速查即可。

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
{
// 包含: /** 任何目录 /* 任何文件 默认值:/**/*
"include": ["./**/*"],
// 排除: 默认排除node_modules browser_components jspm_packages 一般情况下不需要配置
"exclude": [],
"compilerOptions": {
// 用来指定ts被编译后的es版本 默认es3 ESNext指代最新的es版本
"target": "ES5",
// 执行项目中要使用库 一般不用 浏览器环境不用管
// "lib": ["dom"], // 比如dom => document
// 编译后的文件路径
"outDir": "dist",
// 全局作用域中的代码合并放到一起 如果要合并模块 module应该设置amd或者system规范
// "outFile": "./dist/app.js",
// 移除注释
"removeComments": true,

/* Modules */
// 指定要使用的模块化规范 js有很多模块化的解决方案
"module": "ES2015", // 推荐

/* JavaScript Support */
// 是否对js文件进行编译
"allowJs": true,
// 是否对js文件进行类型检查
"checkJs": true,

/* Emit */
// 只是需要ts检测文件的时候 不生成编译后的文件
// "noEmit": false,
// 存在没有通过ts检测的情况 默认false 不会进行编译
// "noEmitOnError": true,

/* Type Checking */
// 开启所有的严格检查 建议开启 为true关于严格检查的会默认开启 不需要的分别设置
"strict": true,

// 用来设置编译后的文件是否使用严格模式 对应的js文件中'use strict'; 浏览器执行效率会更高
// "alwaysStrict": true,
// 不能存在出现隐式的any类型
// "noImplicitAny": true,
// 不能出现类型不明的this 默认false
// "noImplicitThis": true,
// 严格的空值检查 默认false
// "strictNullChecks": true,
// 严格检查函数的类型
// "strictFunctionTypes": true,
// 严格检查 call apply bind的参数列表
// "strictBindCallApply": true,
// 严格检查属性是否初始化
// "strictPropertyInitialization": true

// 检查未使用的局部变量
// "noUnusedLocals": true,
// 检查未使用的参数
// "noUnusedParameters": true,
// 检查函数没有隐式的返回值
// "noImplicitReturns": true,
// 检查不可达代码 true: 忽略; false: 不可达代码将会引起错误
// "allowUnreachableCode": true
}
}