当前位置:网站首页>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的元素
边栏推荐
- 【MySql进阶】索引详解(一):索引数据页结构
- The team of East China Normal University proposed the systematic molecular implementation of convolutional neural network with DNA regulation circuit
- 面向接口编程
- Statistical learning method -- perceptron
- Laravel5.1 Routing - routing packets
- 字节跳动Android金三银四解析,android面试题app
- Logback日志框架第三方jar包 免费获取
- 无法将“pip”项识别为 cmdlet、函数、脚本文件或可运行程序的名称
- 【PHP】PHP接口继承及接口多继承原理与实现方法
- [designmode] proxy pattern
猜你喜欢
Record the migration process of a project
值得一看,面试考点与面试技巧
Vs tool word highlight with margin
Introduction and use of gateway
pycharm 终端部启用虚拟环境
As an Android Developer programmer, Android advanced interview
Binary search tree (features)
【Android -- 数据存储】使用 SQLite 存储数据
DNS 系列(一):为什么更新了 DNS 记录不生效?
1亿单身男女“在线相亲”,撑起130亿IPO
随机推荐
【HCSD大咖直播】亲授大厂面试秘诀-简要笔记
[designmode] proxy pattern
Vs2019 configuration matrix library eigen
Record the migration process of a project
字节跳动高工面试,轻松入门flutter
模仿企业微信会议室选择
面向接口编程
Performance measure of classification model
二叉搜索树(特性篇)
模拟Servlet的本质
谎牛计数(春季每日一题 53)
删除 console 语句引发的惨案
Horizontal and vertical centering method and compatibility
[vulnhub range] thales:1
运算符
面试题 01.02. 判定是否互为字符重排-辅助数组算法
Opportunity interview experience summary
[designmode] template method pattern
【DesignMode】外观模式 (facade patterns)
What is the difference between IP address and physical address