使用命令行创建tsconfig.json文件: tsc -init
1、"include": ["demo.ts",....], // 数组内的文件都编译,与"files"作用相同
"exclue": ["demo.ts",....], // 数组内的文件都不编译
2、"removeComments": true/false 编译出来的js文件是否显示注释
3、"strict" 编译译和书写规范,是否按照TypeScript最严格的规范来写(一般设置为true即可)
若strict为true,则下面的一串(noImplicitAny、strictNullChecks...alwaysStrict)也为true
3.1 noImplicitAny 允许你的注解类型any不用特意表明,若noImplicitAny为true:
function hello(name:any) {return name;} 不能去掉粗体部分
3.2 strictNullChecks:强制检查NULL类型,若noImplicitAny为true:
const usname:string=null; 会报错
4、"outDir": "./build", 编译完成的文件放到哪个目录下
"rootDir": "./src", 要编译的ts文件在哪个目录
5、"sourceMap": true, ts和js文件对应的信息
6、"noUnusedLocals": true, 未使用属性编译会报错
其他配置编译选项查看
网友评论