学习TypeScript(3)
配置文件
tsconfig.json文件
tsconfig.json文件中"removeComments":true就是生成的js文件除去原文件的注释。可运用通配符
生成tsconfig.json文件语句
tsc -init
还要把"removeComments": true, 前面的 // 去掉 才能真正的调用起来。
运行语句
tsc X.ts
include
include表示包含哪个文件去运行生成js文件
在tsconfig.json文件的头顶加上
{
"include":["X.ts"],
..............
}
exclude
exclude 与include相对应,除了哪个文件其他都编译生成js文件
{
"exclude":["X.ts"],
.......................
}
files
files与include相类似,都是生成相应的js文件。
compilerOptions配置项
strict
严格模式;当tsconfig.json文件中此项开启,它以下的参数均为true,不可更改。
{
.......,
"strict":true,
.............
}
假设"strict":false
"noImplicitAny":true //不允许注解类型any不标明
"strictNullChecks": true // 不允许null值的出现
一般编写文件.ts都会放在str文件夹里面;生成编译的js文件都会放在build文件夹里面,那么我们应该在下面配置一下路径。
"rootDir":"./src", //入口ts文件路径
"outDir":"./build" //编译生成js文件路径
修改完成后运行
tsc
帮助在编写代码时找错/排错的配置文件,相当于编写日志。
"sourceMap":true,
详细的配置参数等请移步到官网TypeScript的tsconfig.js配置文件