当前位置:网站首页>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的元素
边栏推荐
- 值得一看,面试考点与面试技巧
- Balanced binary tree (AVL)
- Introduction and use of gateway
- Binary search tree (features)
- Opencv personal notes
- AutoLISP series (3): function function 3
- ATM system
- Build an all in one application development platform, light flow, and establish a code free industry benchmark
- laravel中将session由文件保存改为数据库保存
- MySQL中, 如何查询某一天, 某一月, 某一年的数据
猜你喜欢
spark调优(三):持久化减少二次查询
二叉搜索树(基操篇)
Lecturer solicitation order | Apache seatunnel (cultivating) meetup sharing guests are in hot Recruitment!
【医学分割】attention-unet
Binary search tree (features)
[designmode] facade patterns
【Vulnhub靶场】THALES:1
ByteDance Android gold, silver and four analysis, Android interview question app
Personal notes of graphics (2)
AutoLISP series (2): function function 2
随机推荐
PHP中exit,exit(0),exit(1),exit(‘0’),exit(‘1’),die,return的区别
Unity3d click events added to 3D objects in the scene
Sqlserver2014+: create indexes while creating tables
[PHP] PHP interface inheritance and interface multi inheritance principle and implementation method
Detailed explanation of several ideas for implementing timed tasks in PHP
Laravel 服务提供者实例教程 —— 创建 Service Provider 测试实例
As an Android Developer programmer, Android advanced interview
运算符
Three. JS series (2): API structure diagram-2
Talk about the cloud deployment of local projects created by SAP IRPA studio
Asyncio concept and usage
Set the route and optimize the URL in thinkphp3.2.3
偶然升职的内心独白
【DesignMode】代理模式(proxy pattern)
Binary search tree (features)
three. JS create cool snow effect
Build an all in one application development platform, light flow, and establish a code free industry benchmark
如何快速检查钢网开口面积比是否符合 IPC7525
[Android -- data storage] use SQLite to store data
【C 语言】 题集 of Ⅹ