TypeScript - 配置文件 tsconfig.json

tsconfig.json 文件

创建两种方式:

1. 直接在根目录新建tsconfig.config.json (配置文件需要自己配置)

2. 执行tsc --init  (会自动创建相关配置)

tsc --init
{
  "compilerOptions": {
    // target 用来指定ts被编译为的ES版本
    // '--target' option must be: 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'esnext'.
    "target": "ES6",
    // 指定要使用的模块化的规范
    // '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2020', 'esnext'.
    "module": "System",
    // library 用来指定项目中要使用的库
    // 代码提示
    // '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'webworker.iterable', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.asyncgenerator', 'es2018.asynciterable', 'es2018.intl','es2018.promise', 'es2018.regexp', 'es2019.array', 'es2019.object', 'es2019.string', 'es2019.symbol', 'es2020.bigint', 'es2020.promise', 'es2020.sharedmemory', 'es202.string', 'es2020.symbol.wellknown', 'es2020.intl', 'es2021.promise', 'es2021.string', 'es2021.weakref', 'esnext.array', 'esnext.symbol', 'esnext.asynciterable', 'esnext.intl','esnext.bigint', 'esnext.string', 'esnext.promise', 'esnext.weakref'.
    // "lib": ['dom']

    // outDir 用来指定编译后文件所在的目录
    "outDir": "./dist",

    // outFile 将代码合并为一个文件
    // 设置outFile后,所有全局作用域中的代码 会合并到同一个文件, 但是如果文件中有模块引用,则module需要改为System
    // 该功能一般是打包工具来做,仅作了解,
    "outFile": "./dist/app.js",

    // 是否编辑js文件, 默认false
    "allowJs": true,
    // 是否检查js代码是否符合语法规范
    // js中, let a = 10; a = 'hello'; true的情况下,会变检查
    "checkJs": true,

    // 是否移除注释
    "removeComments": true,

    // 不生成编译后的文件 即dist内的东西
    "noEmit": false,

    // 当有错误的时候,是否生成编译文件,避免编译错误代码
    "noEmitOnError": true,

    // 语法检查相关属性

    // 所有严格检查的总开关, 下面的一些是否启动,即使后面的是true, 如果此处是false,同样不执行
    "strict": true,

    // 用来设置编译后的文件是否启用严格模式,默认false
    "alwaysStrict": true,

    // 否否允许隐式的any类型
    // function sum(a, b){ return a + b } 此处a b就是隐式的any
    "noImplicitAny": true,

    //不允许不明确类型的this
    // function a(){ console.log(this) }
    "noImplicitThis": true,

    // 是否检测null值
    "strictNullChecks": true
  }
}
 

 

posted @ 2021-08-03 14:59  鑫仔Alan  阅读(145)  评论(0编辑  收藏  举报