当前位置:网站首页>typescript ts基础知识之tsconfig.json配置选项
typescript ts基础知识之tsconfig.json配置选项
2022-07-07 14:49:00 【糖糖246】
tsc xxx.ts // 编译xxx.ts文件
tsc xxx.ts -w // 编译并监视xxx.ts文件
tsc // 编译所有ts文件,前提是存在tsconfig.json
tsc -w // 编译并监视所有ts文件,前提是存在tsconfig.json
tsconfig.json是ts的配置文件,里边可以写注释,其常用配置选项如下:
1. include:定义希望被编译文件所在目录,默认值为['**/*'],**表示任意目录,*表示任意文件
"include": [ "./src/**/*" ]2. exclude:不需要被编译的文件目录,默认值为["node_modules", "bower_components", "jspm_packages"]
"exclude": [ "./src/hello/**/*" ]3.extends:定义被继承的配置文件,将不想重复写的配置项引入进来
"extends": "./configs/base"4. files:指定被编译文件的列表,编译文件较少时适用
"files": [
"core.ts",
"tsc.ts",
...
]5. compilerOptions 编译器的选项
"compilerOptions": {
"target": "ES3", //用来指定ts被编译为的es的版本,值为es版本(见下方标注)
"module": "commonjs", //指定要使用的模块化的规范(值见下方标注)
"lib": ["es6", "dom"], //用来指定项目中要用的库,前端运行代码不需要改变其默认值
"outDir": "./dist", //指定编译后文件所在的目录
"outFile": "./dist/app.js", //将代码合并为一个文件,所有的全局作用域中的代码会合并到一个文件中,若想合并多个模块,需要将module的值改为amd或system,可以结合打包工具完成此功能
"allowJs": false, //是否对js文件进行编译,默认是false
"checkJs": false, //是否检查js代码是否符合语法规范,默认是false
"removeComments": false, //是否移除注释
"noEmit": true, //不生成编译后的文件,默认值是false
"noEmitOnError": false, //当有错误时,不生成编译后的文件,默认false
"strict": false, //所有严格检查的总开关,下方四个设置的总开关
"alwaysStrict": false, //用来设置编译后的文件是否使用严格模式,默认false
"noImplicitAny": false, //不允许隐式的any类型,默认false
"noImlicitThis": false, //不允许不明确类型的this,默认false
"strictNullChecks": false, //严格的检查空值
}
注:
1.es目前版本值:'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'es2022', 'esnext'
2. module可用值为:'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2020', 'es2022', 'esnext', 'node16', 'nodenext'
3. 当"noImlicitThis": true时
function fn(this: Window){ console.log(this) }
4. "strictNullChecks": true时
let box = document.getElementById('box')
box.addEventListener('click', function(){...}) //此时box报错,因为可能没有id为box的元素
边栏推荐
- PHP中exit,exit(0),exit(1),exit(‘0’),exit(‘1’),die,return的区别
- [C language] question set of X
- ThinkPHP URL 路由简介
- 模拟Servlet的本质
- MySQL中, 如何查询某一天, 某一月, 某一年的数据
- C语言进阶——函数指针
- ATM系统
- Three. JS series (1): API structure diagram-1
- 【知识小结】PHP使用svn笔记总结
- How does laravel run composer dump autoload without emptying the classmap mapping relationship?
猜你喜欢

运算符

【DesignMode】代理模式(proxy pattern)

删除 console 语句引发的惨案

Imitate the choice of enterprise wechat conference room

无法将“pip”项识别为 cmdlet、函数、脚本文件或可运行程序的名称
![[designmode] proxy pattern](/img/ed/642aebc7b49cbf4d30b517665b2438.png)
[designmode] proxy pattern
作为Android开发程序员,android高级面试

Personal notes of graphics (2)

华东师大团队提出,具有DNA调控电路的卷积神经网络的系统分子实现

Sysom case analysis: where is the missing memory| Dragon lizard Technology
随机推荐
目标跟踪常见训练数据集格式
3000 words speak through HTTP cache
Tidb cannot start after modifying the configuration file
Introduction to ThinkPHP URL routing
Opencv personal notes
[PHP] PHP interface inheritance and interface multi inheritance principle and implementation method
three.js打造酷炫下雪效果
Statistical learning method -- perceptron
logback.xml配置不同级别日志,设置彩色输出
Set the route and optimize the URL in thinkphp3.2.3
Inner monologue of accidental promotion
PHP实现微信小程序人脸识别刷脸登录功能
time标准库
Description of vs common shortcut keys
【C 语言】 题集 of Ⅹ
模仿企业微信会议室选择
"The" "PIP" "entry cannot be recognized as the name of a cmdlet, function, script file, or runnable program."
23. 合并K个升序链表-c语言
AutoLISP series (1): function function 1
laravel 是怎么做到运行 composer dump-autoload 不清空 classmap 映射关系的呢?