TypeScript的配置文件tsconfig.json

参考网址:TypeScript: Documentation - What is a tsconfig.json (typescriptlang.org)

TypeScript: TSConfig Reference - Docs on every TSConfig option (typescriptlang.org) 

一、去掉注释

tsconfig.json初始是这样的

// "removeComments": true,

1、把注释取消掉

"removeComments": true,

2、运行tsc命令

tsc

生成的JS文件中没有注释

"removeComments": true,中true改为false,则不移除注释

3、tsc filename这个命令不会调用配置文件,所以这个命令生成的JS文件是默认配置

二、编译指定文件

在tsconfig.json中增加配置

"include": ["./index.ts"],

"compilerOptions": {

        ...

}

tsc命令只编译index.ts文件,要增加文件在数组中添加即可

如:

"include": ["./index.ts","./a.tx"],

"compilerOptions": {

        ...

}

三、不编译指定文件

"exclude": ["./index.ts","./a.tx"],

"compilerOptions": {

        ...

}

 四、显示指定any

"noImplicitThis": true,

Implicit---->adj.  不言明[含蓄]的; 无疑问的,绝对的; 成为一部份的; 内含的;

五、null类型只能赋值给Object

"strictNullChecks": true,    

报错:error TS2322: Type 'null' is not assignable to type 'string'

strictNullChecks为true时,null不能赋值给其他类型

六、把指定源目录中的TS文件编译到指定目标目录中

指定TS源目录

    "rootDir": "./src",                                  /* Specify the root folder within your source files. */

指定JS目标目录

    "outDir": "./build",                                   /* Specify an output folder for all emitted files. */

七、只编译新内容,渐进式编译/增量式编译

    "incremental": true,  /* Save .tsbuildinfo files to allow for incremental compilation of projects. */

 设置为true后运行tsc会产生一个文件tsconfig.tsbuildinfo,里面记录了上一次编译的具体信息,下一次编译时会对照这个文件,只编译新内容

八、允许编译JS文件

    "allowJs": true,  /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */

设置为true后,源目录中的JS文件也会被编译

九、检查JS文件的语法

    "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */

十、编译时生成.map文件

    "sourceMap": true, /* Create source map files for emitted JavaScript files. */

十一、从未使用的局部变量报错

    "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */

 十二、从未使用的函数参数报错

    "noUnusedParameters": true,/* Raise an error when a function parameter isn't read. */

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值