tsconfig的配置记录

2,333 阅读11分钟

typescript愈发成为必备的开发技能, 基本上时拿来即用, 对于一些配置并没有很深入的理解, 趁着现在有时间了, 可以好好过一遍, 我在这里会对一些我认为比较不常用的做一些解释, 可能不够全面, 请到这里查看所有的配置: json.schemastore.org/tsconfig.

compileoption

基本配置

strict

当启用严格模式时, 默认时启用了下列条件

  • noImplicitAny 不允许隐式any
  • noImplicitThis this值为any时报错
  • alwaysStrict 以严格模式编译模块, 且会在生成的js文件的顶部添加 'use strict'
  • strictNullChecks null和undefined不允许赋值给非null和undefined的值(undefined可以赋值给void除外), 反之除了any亦然, unknown不在这个限制中
  • strictFunctionTypes 检查函数参数双向协变
function makeLowerCase(s: string) { return s.toLowerCase(); }
declare let foo: Promise<string|number>;
foo.then(makeLowerCase)

只有设置检查双向协变时能够检查出类型不兼容报错, 点击此处查看什么是函数协变, 还有一个概念是逆变, 简单来说, 协变是使类型更具体, 逆变是使类型更宽泛, 数据只读时协变是安全的, 数据只可写时, 逆变是安全的, 当可读可写时, 两者都不可使用

  • strictPropertyInitialization 是否在初始值类型为非null或undefined的值设置初始值, 设置为true时需要开启strictNullChecks

target

定义ECMAScript的版本, 默认为ES3, 有以下选项可选 'ES3', 'ES5', 'ES6'/'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ESNext'

lib

应该被包含进编译器的库文件, 包括以下可选项

  • "ES5",
  • "ES6",
  • "ES7",
  • "ES2015",
  • "ES2015.Collection",
  • "ES2015.Core",
  • "ES2015.Generator",
  • "ES2015.Iterable",
  • "ES2015.Promise",
  • "ES2015.Proxy",
  • "ES2015.Reflect",
  • "ES2015.Symbol.WellKnown",
  • "ES2015.Symbol",
  • "ES2016",
  • "ES2016.Array.Include",
  • "ES2017",
  • "ES2017.Intl",
  • "ES2017.Object",
  • "ES2017.SharedMemory",
  • "ES2017.String",
  • "ES2017.TypedArrays",
  • "ES2018",
  • "ES2018.AsyncIterable",
  • "ES2018.Intl",
  • "ES2018.Promise",
  • "ES2018.Regexp",
  • "ES2019",
  • "ES2019.Array",
  • "ES2019.Object",
  • "ES2019.String",
  • "ES2019.Symbol",
  • "ES2020",
  • "ES2020.BigInt",
  • "ES2020.Promise",
  • "ES2020.String",
  • "ES2020.Symbol.WellKnown",
  • "ESNext",
  • "ESNext.Array",
  • "ESNext.AsyncIterable",
  • "ESNext.BigInt",
  • "ESNext.Intl",
  • "ESNext.Symbol",
  • "DOM",
  • "DOM.Iterable",
  • "ScriptHost",
  • "WebWorker",
  • "WebWorker.ImportScripts"

declaration

是否在编译的时候为模块生成一个.d.ts的声明文件.不能与allowJs同时设为true.

outFile

指定输出的文件合并为一个文件, 仅在module: 'system'|'amd'生效

outDir

输出文件要放置的文件夹

suppressExcessPropertyErrors && suppressImplicitAnyIndexErrors

用于检查对象字面量是否允许额外的定义

let a = {name: 'lorry'}

a = {name: 'lorry', age: 18} // 当设置为true时不会报错, 允许额外定义, 当设置为false时会报 '只允许定义已知属性'的错误
// 但是如果缺少属性不行
a = {age: 18} // 报错, 缺少name的定义

这里有个问题, 虽然a在重新定义之后多了一个age属性, 但是之后的使用中并没有这个age的类型推断, 使用a.age也会报错, 非严格模式下使用a['age']是可以的.或者严格模式下, 在设置了suppressImplicitAnyIndexErrorstrue时也是可以通过a['age']来实现访问的, 该特性表示: 是否阻止当索引访问缺少索引签名的对象时非隐式any的报错

模块解析选项

moduleResolution

模块解析策略, 仅 nodeclassic 可选, 只需要使用npm安装的第三方库就需要指定为 node, classic多用于向后兼容

baseUrl

非相对路径时的base路径, 非相对路径指非以下三种开头的导入

  • /
  • ./
  • ../

比如将baseUrl设置为 './src', 那么之后引用 import A from 'moduleA' 时会默认先查找./src下有无该模块, 没有再去node_modules中查找, 这里很重要的是模块的查找算法, 有两种, node和classic, 详细的区别可参见 www.tslang.cn/docs/handbo…

这里需要与rootDirs进行一下区分,

paths

模块名基于baseUrl的路径映射

{
    path:{
        jquery: './src/modules/jquery'
    }
}

rootDirs

因为rootDirs是指定了一个root的列表,参见官网的例子

src
└── views
    └── view1.ts (imports './template1')
    └── view2.ts

generated
└── templates
        └── views
            └── template1.ts (imports './view2')

如果将./src/view./generated/templates/views都设置为rootDirs, 那么打包之后会把这两个文件夹下的合并在一起, 那两个import语句就不会报错了. 请注意, 使用该属性并不会将两者对rootDirs里面的路径进行打包整合, 他是默认为在运行时是会合并的, 至于如何合并, 是打包时候的事情了

"rootDirs" specify a list of roots whose contents are expected to merge at run-time.

typeRoot

值为数组, 用于指定声明文件或文件夹的路径列表, 如果配置了该项, 那么只有这里面匹配的声明文件才会被加载

types

值为数组, 用于指定要加载类型的模块名称, 只有在该数组下的模块才会加载声明文件(最终影响的只是声明文件, 并未影响模块的加载)

rootDir

值为字符串, 告诉编译器相对路径的根目录

如果rootDir下没有完全包含includefile字段涉及的文件, 编译过程会报错, 但是不会中断编译

forceConsistentCasingInFileNames

禁止对同一个文件的不一致引用, 查询了相关资料, 还是没有找到具体的例子, 只是有些issue是说在跨平台的时候会因为路径查找的问题发生错误.比如 github.com/microsoft/T… 但是我试了下升级到3.3.1版本以上可以整除编译. 这个字段以后遇到再看看, 先行略过

composite

是否构建引用项目, 与reference联合使用

isolatedModules

是否将每个文件作为单独的模块, 如果设置为true(默认), 不能与declaration同时使用

noErrorTruncation

这是在调试时非常有用的参数, 比如一个很长的列表, vscode代码提示时会缩减一部分, 用...(省略号)代替, 那么就无法看清究竟是哪里除了问题, 将这个参数设置为true就可以避免这个问题了, 不要缩减报错信息

下图是默认的代码提示:

下图是设置为true的提示:

allowSyntheticDefaultImports

允许对没有默认导出的模块使用默认导入, 这不影响代码生成, 只是为了类型检查. 注意这里的默认值不是固定的, 而是按照module === "system" or --esModuleInterop来决定.

当该值为false时

因为react的导出为commonjs的方式

影响代码生成的是esModuleInterop字段, 默认会将allowSyntheticDefaultImports 设置为true, 在生成的代码中会多一个兼容函数 __importDefault

var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importDefault(require("react"));

不过一般是结合webpack一起使用, 且通常会将tsconfig里面的module设置为es2015以上(会忽略esModuleInterop字段), webpack会进行对应引用, 也就是这里只需要设置allowSyntheticDefaultImports来保证类型检查即可

esModuleInterop

是否为导入的模块创建命名空间, 实现commonjs和es模块之间的互操作性, 其提供了 __importStar__importDefault 两个帮助函数

source 相关

sourceRoot

定义在调试时应该定位的ts文件路径而不是源路径, 值为一个字符串, 该值会被写进.map文件里

mapRoot

定义调试时应该定位的源文件而不是生成文件的位置, 指定map文件的根路径, 该值会影响.map文件的source属性

inlineSourcesMap

是否生成一个包含sorce-map在一起的单文件还是分开的js,如果设置为true, 生成的js底部会以//#sourceMappingURL=base64的字符串

inlineSources

是否将ts文件的内容也包含到js文件中

实验室

experimentalDecorators

是否开启实验室的对ES7的装饰器支持

emitDecoratorMetadata

装饰器元数据的支持, 可以访问Reflect提供的静态方法, 需要在lib中加入es2015.Reflect这个库

其他检查

noImplicitReturns

是否要求所有的函数代码必须有返回值

// 设置为true时会报错
function a() {
  if(1 > 2) {
    return 'aaa'
  }
}

noUnusedLocals

是否允许未使用的变量, 可以配置eslint

noUnusedParameters

是否允许未使用的函数参数,可以配置eslint

noFallthroughCasesInSwitch

是否允许贯穿的switch-case

let a = 10
switch (a % 2) {
  case 0: // 报错, throughCase
    console.log(0)
  case 1:
    break;
}
// 只有在非空语句中才会检查, 下列代码不会报错
switch (a % 2) {
  case 0:
  case 1:
    break;
}

files

  • 该字段对应值为 string[]
  • 配置了该字段会只编译该字段下的文件
  • 未配置的话是否有include
    • 没有对根目录下的所有文件进行编译
    • 走include的逻辑
  • 必须是指定文件, 不能是文件夹, 不能使用 * ? ** 等通配符

include

  • 该字段对应值为string[]
  • 配置了该字段只会编译符合规则路径的文件及文件夹
  • 指定的路径可以是文件夹也可以是文件, 允许使用通配符

exclude

  • 该字段对应值为string[]
  • 配置了该字段不会编译符合规则路径的文件及文件夹
  • 指定的路径可以是文件夹也可以是文件, 允许使用通配符

extends

  • 指定其他的tsconfig.json
  • 相同的配置项会覆盖当前配置
  • 3.2版本之后支持npm的tsconfig配置

compileOnSave

  • 字段值为true或者false
  • 保存时编译, 需浏览器支持
  • 较消耗性能

references

  • 字段值为object[], object的值为包含tsconfig的文件夹文件的路径
  • 需3.0版本以上

完整版配置

以下是根据官网的tsconfig schema的全部字段翻译, 供参考

{
  "title": "JSON schema for the TypeScript compiler's configuration file",
  "$schema": "http://json-schema.org/draft-04/schema#",
  "definitions": {
    "filesDefinition": {
      "properties": {
        "files": {
          "description": "如果没有files或include属性, 那么就默认会使用除了exclude之外的所有该目录及子目录下的所有文件进行编译. 如果有则使用files和includes中的文件",
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "excludeDefinition": {
      "properties": {
        "exclude": {
          "description": "定义一个不需要编译的文件列表, 只能排除include字段指定的文件而不能排除files的.全局模式需要2.0版本以上",
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "includeDefinition": {
      "properties": {
        "include": {
          "description": "定义一个全局模式的包含列表",
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "compileOnSaveDefinition": {
      "properties": {
        "compileOnSave": {
          "description": "是否启用保存时编译功能",
          "type": "boolean"
        }
      }
    },
    "extendsDefinition": {
      "properties": {
        "extends": {
          "description": "要进行继承的基本文件, 2.1版本以上",
          "type": "string"
        }
      }
    },
    "compilerOptionsDefinition": {
      "properties": {
        "compilerOptions": {
          "type": "object",
          "description": "如何编译.ts文件的指令",
          "properties": {
            "charset": {
              "description": "输入文件的字符集",
              "type": "string"
            },
            "composite": {
              "description": "为项目引用启用构建",
              "type": "boolean"
            },
            "declaration": {
              "description": "是否生成响应式的d.ts文件",
              "type": "boolean"
            },
            "declarationDir": {
              "description": "定义生成声明文件的输出目录, 需要2.0以上",
              "type": [
                "string",
                "null"
              ]
            },
            "diagnostics": {
              "description": "是否展示诊断信息",
              "type": "boolean"
            },
            "emitBOM": {
              "description": "在输出文件前生成一个utf-8的BOM(字节顺序标记)",
              "type": "boolean"
            },
            "emitDeclarationOnly": {
              "description": "是否只在'd.ts'前生成标记",
              "type": "boolean"
            },
            "incremental": {
              "description": "是否开启增量编译",
              "type": "boolean"
            },
            "tsBuildInfoFile": {
              "description": "定义文件来储存增量编译信息",
              "type": "string"
            },
            "inlineSourceMap": {
              "description": "是否生成一个sorce-map包含在一起的单文件还是分开",
              "type": "boolean"
            },
            "inlineSources": {
              "description": "触发source和source-map在单个文件中, 需要设置--inlineSourceMap",
              "type": "boolean"
            },
            "jsx": {
              "description": "定义jsx代码的生成: 'preserve', 'react', or 'react-native'.",
              "enum": [
                "preserve",
                "react",
                "react-native"
              ]
            },
            "reactNamespace": {
              "description": "定义当target为'react'时为了createElement和__spread而触发的对象",
              "type": "string"
            },
            "listFiles": {
              "description": "是否打印编译的文件名",
              "type": "boolean"
            },
            "mapRoot": {
              "description": "定义调试时应该定位的源文件而不是生成的位置",
              "type": "string"
            },
            "module": {
              "description": "定义模块代码的生成: 'None', 'CommonJS', 'AMD', 'System', 'UMD', 'ES6', 'ES2015', 'ES2020' or 'ESNext'. 只有 'AMD' 和 'System' 能够与 --outFile 连用.",
              "type": "string",
              "anyOf": [
                {
                  "enum": [
                    "CommonJS",
                    "AMD",
                    "System",
                    "UMD",
                    "ES6",
                    "ES2015",
                    "ES2020",
                    "ESNext",
                    "None"
                  ]
                },
                {
                  "pattern": "^([Cc][Oo][Mm][Mm][Oo][Nn][Jj][Ss]|[AaUu][Mm][Dd]|[Ss][Yy][Ss][Tt][Ee][Mm]|[Ee][Ss]([356]|201[567]|2020|[Nn][Ee][Xx][Tt])|[Nn][Oo][Nn][Ee])$"
                }
              ]
            },
            "newLine": {
              "description": "定义结束符为: 'crlf' (Windows) or 'lf' (Unix).",
              "type": "string",
              "anyOf": [
                {
                  "enum": [
                    "crlf",
                    "lf"
                  ]
                },
                {
                  "pattern": "^(CRLF|LF|crlf|lf)$"
                }
              ]
            },
            "noEmit": {
              "description": "是否不触发输出",
              "type": "boolean"
            },
            "noEmitHelpers": {
              "description": "是否在输出的文件中不生成自定义帮助函数, 比如__extends.",
              "type": "boolean"
            },
            "noEmitOnError": {
              "description": "是否在任意类型检查错误的时候不输出",
              "type": "boolean"
            },
            "noImplicitAny": {
              "description": "是否在隐式any中显示告警",
              "type": "boolean"
            },
            "noImplicitThis": {
              "description": "是否当this为隐式any类型时抛出错误",
              "type": "boolean"
            },
            "noUnusedLocals": {
              "description": "在未使用的本地变量时报错, 2.0版本以上",
              "type": "boolean"
            },
            "noUnusedParameters": {
              "description": "未使用的参数时报错2.0版本以上",
              "type": "boolean"
            },
            "noLib": {
              "description": "是否不包含默认库文件(lib.d.ts).",
              "type": "boolean"
            },
            "noResolve": {
              "description": "是否在编译好的文件列表中不添加三斜杠(///)或者模块导入对象",
              "type": "boolean"
            },
            "noStrictGenericChecks": {
              "description": "在函数类型的标签中禁用严格类型检查",
              "type": "boolean"
            },
            "skipDefaultLibCheck": {
              "type": "boolean"
            },
            "skipLibCheck": {
              "description": "跳过声明文件的类型检查",
              "type": "boolean"
            },
            "outFile": {
              "description": "组合并输出一个单文件",
              "type": "string"
            },
            "outDir": {
              "description": "重定向输出结构到指定目录",
              "type": "string"
            },
            "preserveConstEnums": {
              "description": "在生成的代码中不擦除const enum的定义.",
              "type": "boolean"
            },
            "preserveSymlinks": {
              "description": "不要解析符号链接到真正的路径, 把这个符号文件当成真正的一个",
              "type": "boolean"
            },
            "preserveWatchOutput": {
              "description": "是否在发现文件更新时保留之前的console",
              "type": "boolean"
            },
            "pretty": {
              "description": "(实验室特性)格式化错误和消息",
              "type": "boolean"
            },
            "removeComments": {
              "description": "不要在输出中触发注释",
              "type": "boolean"
            },
            "rootDir": {
              "description": "定义输入文件的根路径, 用于控制输出目录结构的使用 --outDir.",
              "type": "string"
            },
            "isolatedModules": {
              "description": "是否允许孤立的模块",
              "type": "boolean"
            },
            "sourceMap": {
              "description": "是否生成'.map' 文件.",
              "type": "boolean"
            },
            "sourceRoot": {
              "description": "定义在调试时应该定位的ts文件路径而不是源路径",
              "type": "string"
            },
            "suppressExcessPropertyErrors": {
              "description": "是否阻止对象字面量的额外属性检查",
              "type": "boolean"
            },
            "suppressImplicitAnyIndexErrors": {
              "description": "是否阻止当索引访问缺少索引签名的对象时非隐式any的报错",
              "type": "boolean"
            },
            "stripInternal": {
              "description": "是否为拥有'@internal'注释的代码不触发声明",
              "type": "boolean"
            },
            "target": {
              "description": "定义ECMAScript的版本Specify ECMAScript target version: 'ES3', 'ES5', 'ES6'/'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ESNext'",
              "type": "string",
              "default": "ES3",
              "anyOf": [
                {
                  "enum": [
                    "ES3",
                    "ES5",
                    "ES6",
                    "ES2015",
                    "ES2016",
                    "ES2017",
                    "ES2018",
                    "ES2019",
                    "ES2020",
                    "ESNext"
                  ]
                },
                {
                  "pattern": "^([Ee][Ss]([356]|(20(1[56789]|20))|[Nn][Ee][Xx][Tt]))$"
                }
              ]
            },
            "watch": {
              "description": "需要观察的输入文件们",
              "type": "boolean"
            },
            "experimentalDecorators": {
              "description": "是否开启实验室的对ES7的装饰器支持",
              "type": "boolean"
            },
            "emitDecoratorMetadata": {
              "description": "为装饰器声明源码中加入设计类型的元数据",
              "type": "boolean"
            },
            "moduleResolution": {
              "description": "定义模块解析策略'node' (Node) or 'classic' (TypeScript 1.6 版本前) .",
              "type": "string",
              "anyOf": [
                {
                  "enum": [
                    "Classic",
                    "Node"
                  ]
                },
                {
                  "pattern": "^(([Nn]ode)|([Cc]lassic))$"
                }
              ],
              "default": "classic"
            },
            "allowUnusedLabels": {
              "type": "boolean",
              "description": "不要对未使用的标签报错"
            },
            "noImplicitReturns": {
              "description": "是否允许有的函数代码没有返回值",
              "type": "boolean"
            },
            "noFallthroughCasesInSwitch": {
              "description": "是否允许不完整的switch-case",
              "type": "boolean"
            },
            "allowUnreachableCode": {
              "description": "是否允许到达不了的代码存在",
              "type": "boolean"
            },
            "forceConsistentCasingInFileNames": {
              "description": "禁止对同一个文件的不一致的引用",
              "type": "boolean"
            },
            "baseUrl": {
              "description": "非相对路径时的base路径, /, ./, ../等都是相对路径",
              "type": "string"
            },
            "paths": {
              "description": "相对于baseUrl设置定义路径查找",
              "type": "object",
              "additionalProperties": {
                "type": "array",
                "items": {
                  "type": "string",
                  "description": "Path mapping to be computed relative to baseUrl option."
                }
              }
            },
            "plugins": {
              "description": "ts语言服务器插件的加载列表, 需要2.3版本以上",
              "items": {
                "type": "object",
                "properties": {
                  "name": {
                    "description": "插件名称",
                    "type": "string"
                  }
                }
              }
            },
            "rootDirs": {
              "description": "使用模块解析时定义的根目录列表",
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "typeRoots": {
              "description": "定义类型定义文件的文件夹列表, 2.0版本以上",
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "types": {
              "description": "需要被包含的类型定义的文件, 2.0版本以上",
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "traceResolution": {
              "description": "启用名字解析流程追踪",
              "type": "boolean"
            },
            "allowJs": {
              "description": "允许js文件被编译",
              "type": "boolean"
            },
            "noErrorTruncation": {
              "description": "不要删减报错信息",
              "type": "boolean"
            },
            "allowSyntheticDefaultImports": {
              "description": "允许对没有默认导出的模块使用默认导入, 这不影响代码生成, 只是为了类型检查",
              "type": "boolean"
            },
            "noImplicitUseStrict": {
              "description": "是否不在模块的输出中添加'use strict'指令",
              "type": "boolean"
            },
            "listEmittedFiles": {
              "description": "是否启用列表显示所有输出的文件(2.0版本以上)",
              "type": "boolean"
            },
            "disableSizeLimit": {
              "description": "禁止js项目的大小限制",
              "type": "boolean",
              "default": false
            },
            "lib": {
              "description": "应该被包含进编译器的库文件们, 可能的值为 'ES5', 'ES6', 'ES2015', 'ES7', 'ES2016', 'ES2017', 'ES2018', 'ESNext', 'DOM', 'DOM.Iterable', 'WebWorker', '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.Intl', 'ES2017.SharedMemory', 'ES2017.String', 'ES2017.TypedArrays', 'ES2018.Intl', 'ES2018.Promise', 'ES2018.RegExp', 'ESNext.AsyncIterable', 'ESNext.Array', 'ESNext.Intl', 'ESNext.Symbol'. 需要2.0版本以上",
              "type": "array",
              "items": {
                "type": "string",
                "anyOf": [
                  {
                    "enum": [
                      "ES5",
                      "ES6",
                      "ES7",
                      "ES2015",
                      "ES2015.Collection",
                      "ES2015.Core",
                      "ES2015.Generator",
                      "ES2015.Iterable",
                      "ES2015.Promise",
                      "ES2015.Proxy",
                      "ES2015.Reflect",
                      "ES2015.Symbol.WellKnown",
                      "ES2015.Symbol",
                      "ES2016",
                      "ES2016.Array.Include",
                      "ES2017",
                      "ES2017.Intl",
                      "ES2017.Object",
                      "ES2017.SharedMemory",
                      "ES2017.String",
                      "ES2017.TypedArrays",
                      "ES2018",
                      "ES2018.AsyncIterable",
                      "ES2018.Intl",
                      "ES2018.Promise",
                      "ES2018.Regexp",
                      "ES2019",
                      "ES2019.Array",
                      "ES2019.Object",
                      "ES2019.String",
                      "ES2019.Symbol",
                      "ES2020",
                      "ES2020.BigInt",
                      "ES2020.Promise",
                      "ES2020.String",
                      "ES2020.Symbol.WellKnown",
                      "ESNext",
                      "ESNext.Array",
                      "ESNext.AsyncIterable",
                      "ESNext.BigInt",
                      "ESNext.Intl",
                      "ESNext.Symbol",
                      "DOM",
                      "DOM.Iterable",
                      "ScriptHost",
                      "WebWorker",
                      "WebWorker.ImportScripts"
                    ]
                  },
                  {
                    "pattern": "^[Ee][Ss]5|[Ee][Ss]6|[Ee][Ss]7$"
                  },
                  {
                    "pattern": "^[Ee][Ss]2015(\\.([Cc][Oo][Ll][Ll][Ee][Cc][Tt][Ii][Oo][Nn]|[Cc][Oo][Rr][Ee]|[Gg][Ee][Nn][Ee][Rr][Aa][Tt][Oo][Rr]|[Ii][Tt][Ee][Rr][Aa][Bb][Ll][Ee]|[Pp][Rr][Oo][Mm][Ii][Ss][Ee]|[Pp][Rr][Oo][Xx][Yy]|[Rr][Ee][Ff][Ll][Ee][Cc][Tt]|[Ss][Yy][Mm][Bb][Oo][Ll].[Ww][Ee][Ll][Ll][Kk][Nn][Oo][Ww][Nn]|[Ss][Yy][Mm][Bb][Oo][Ll]))?$"
                  },
                  {
                    "pattern": "^[Ee][Ss]2016(\\.[Aa][Rr][Rr][Aa][Yy].[Ii][Nn][Cc][Ll][Uu][Dd][Ee])?$"
                  },
                  {
                    "pattern": "^[Ee][Ss]2017(\\.([Ii][Nn][Tt][Ll]|[Oo][Bb][Jj][Ee][Cc][Tt]|[Ss][Hh][Aa][Rr][Ee][Dd][Mm][Ee][Mm][Oo][Rr][Yy]|[Ss][Tt][Rr][Ii][Nn][Gg]|[Tt][Yy][Pp][Ee][Dd][Aa][Rr][Rr][Aa][Yy][Ss]))?$"
                  },
                  {
                    "pattern": "^[Ee][Ss]2018(\\.([Aa][Ss][Yy][Nn][Cc][Ii][Tt][Ee][Rr][Aa][Bb][Ll][Ee]|[Ii][Nn][Tt][Ll]|[Pp][Rr][Oo][Mm][Ii][Ss][Ee]|[Rr][Ee][Gg][Ee][Xx][Pp]))?$"
                  },
                  {
                    "pattern": "^[Ee][Ss]2019(\\.([Aa][Rr][Rr][Aa][Yy]|[Oo][Bb][Jj][Ee][Cc][Tt]|[Ss][Tt][Rr][Ii][Nn][Gg]|[Ss][Yy][Mm][Bb][Oo][Ll]))?$"
                  },
                  {
                    "pattern": "^[Ee][Ss]2020(\\.([Bb][Ii][Gg][Ii][Nn][Tt]|[Pp][Rr][Oo][Mm][Ii][Ss][Ee]|[Ss][Tt][Rr][Ii][Nn][Gg]|[Ss][Yy][Mm][Bb][Oo][Ll].[Ww][Ee][Ll][Ll][Kk][Nn][Oo][Ww][Nn]))?$"
                  },
                  {
                    "pattern": "^[Ee][Ss][Nn][Ee][Xx][Tt](\\.([Aa][Rr][Rr][Aa][Yy]|[Aa][Ss][Yy][Nn][Cc][Ii][Tt][Ee][Rr][Aa][Bb][Ll][Ee]|[Bb][Ii][Gg][Ii][Nn][Tt]|[Ii][Nn][Tt][Ll]|[Ss][Yy][Mm][Bb][Oo][Ll]))?$"
                  },
                  {
                    "pattern": "^[Dd][Oo][Mm](\\.[Ii][Tt][Ee][Rr][Aa][Bb][Ll][Ee])?$"
                  },
                  {
                    "pattern": "^[Ss][Cc][Rr][Ii][Pp][Tt][Hh][Oo][Ss][Tt]$"
                  },
                  {
                    "pattern": "^[Ww][Ee][Bb][Ww][Oo][Rr][Kk][Ee][Rr](\\.[Ii][Mm][Pp][Oo][Rr][Tt][Ss][Cc][Rr][Ii][Pp][Tt][Ss])?$"
                  }
                ]
              }
            },
            "strictNullChecks": {
              "description": "启用严格的null检查, 需要2.0版本以上",
              "type": "boolean"
            },
            "maxNodeModuleJsDepth": {
              "description": "在搜索node_modules时依赖和加载js时最大深度, 只在allowJs配置生效时有效",
              "type": "number",
              "default": 0
            },
            "importHelpers": {
              "description": "从tslib中导入输出助手 (e.g. '__extends', '__rest', etc..) 需要2.1版本以上",
              "type": "boolean"
            },
            "importsNotUsedAsValues": {
              "description": "定义仅仅为了使用类型的导出/检查行为",
              "type": "string",
              "default": "remove",
              "enum": [
                "remove",
                "preserve",
                "error"
              ]
            },
            "jsxFactory": {
              "description": "定义当目标是react JSX时触发的工厂函数 比如. 'React.createElement' or 'h'. 2.1版本以上",
              "type": "string",
              "default": "React.createElement"
            },
            "alwaysStrict": {
              "description": "是否在所有生成的文件中添加 'use strict' 2.1版本以上",
              "type": "boolean"
            },
            "strict": {
              "description": "是否启用所有的严格类型检查选项, 2.3版本以上",
              "type": "boolean"
            },
            "strictBindCallApply": {
              "description": "是否为`bind`, `call`, 和 `apply`启用更严格的检查",
              "type": "boolean"
            },
            "downlevelIteration": {
              "description": "为当target为'ES5'或'ES3'时在'for-of'中的迭代器, spread, destructuring提供完全的支持. 2.3版本以上.",
              "type": "boolean"
            },
            "checkJs": {
              "description": "报告.js文件的错误,2.3版本以上",
              "type": "boolean"
            },
            "strictFunctionTypes": {
              "description": "在检查函数类型时禁止参数协变, 2.6版本以上",
              "type": "boolean"
            },
            "strictPropertyInitialization": {
              "description": "保证所有非undefined的类属性都必须在constructor中进行初始化, 2.7版本以上",
              "type": "boolean"
            },
            "esModuleInterop": {
              "description": "为运行时babel生态系统的兼容输出'__importStar' 和 '__importDefault' 帮助函数 并且启用 '--allowSyntheticDefaultImports' 为类型系统兼容性, 需要2.7版本以上",
              "type": "boolean"
            },
            "allowUmdGlobalAccess": {
              "description": "允许在模块中访问UMD全局变量",
              "type": "boolean"
            },
            "keyofStringsOnly": {
              "description": "将'keyof'的类型只解析为string, 没有数字或symbols, 2.9版本以上",
              "type": "boolean"
            },
            "useDefineForClassFields": {
              "description": "是否输出标准的ECMAScript类字段,3.7版本以上",
              "type": "boolean"
            },
            "declarationMap": {
              "description": "为每个相对应的'.d.dts'生成一个sourcemap, 需要2.9版本以上",
              "type": "boolean"
            },
            "resolveJsonModule": {
              "description": "是否包括'.json'扩展为模块, 需要2.9版本以上",
              "type": "boolean"
            },
            "assumeChangesOnlyAffectDirectDependencies": {
              "description": "当有再编译时, 只要设置了'--incremental' 和 '--watch' , 那么假设一个文件有更改, 是否仅仅只影响直接依赖这个文件的文件.",
              "type": "boolean"
            }
          }
        }
      }
    },
    "typeAcquisitionDefinition": {
      "properties": {
        "typeAcquisition": {
          "type": "object",
          "description": "是否为该项目设置自动类型(.d.ts) 获取. 2.1版本之后",
          "properties": {
            "enable": {
              "description": "启用自动类型获取",
              "type": "boolean",
              "default": false
            },
            "include": {
              "description": "定义一个需要被自动类型获取的类型声明列表, 比如. [\"jquery\", \"lodash\"]",
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "exclude": {
              "description": "定义一个不需要被自动类型获取的类型声明列表, 比如. [\"jquery\", \"lodash\"]",
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    "referencesDefinition": {
      "properties": {
        "references": {
          "type": "array",
          "description": "引用项目, 需要3.0版本以上",
          "items": {
            "type": "object",
            "description": "Project reference.",
            "properties": {
              "path": {
                "type": "string",
                "description": "包含tsconfig的文件夹文件的路径"
              }
            }
          }
        }
      }
    },
    "tsNodeDefinition": {
      "properties": {
        "ts-node": {
          "description": "ts-node options.  See also: https://github.com/TypeStrong/ts-node#configuration-options\n\nts-node offers TypeScript execution and REPL for node.js, with source map support.",
          "properties": {
            "compiler": {
              "default": "typescript",
              "description": "定义一个自定义ts编译器",
              "type": "string"
            },
            "compilerHost": {
              "default": false,
              "description": "使用ts编译器的host API",
              "type": "boolean"
            },
            "compilerOptions": {
              "additionalProperties": true,
              "allOf": [
                {
                  "$ref": "#/definitions/compilerOptionsDefinition/properties/compilerOptions"
                }
              ],
              "description": "与编译器选项合并的json对象",
              "properties": {},
              "type": "object"
            },
            "emit": {
              "default": false,
              "description": "是否输出文件到`.ts-node` 路径.",
              "type": "boolean"
            },
            "files": {
              "default": false,
              "description": "是否在启动时加载`tsconfig.json`",
              "type": "boolean"
            },
            "ignore": {
              "default": "/node_modules/",
              "description": "覆盖在编译时跳过的路径",
              "items": {
                "type": "string"
              },
              "type": "array"
            },
            "ignoreDiagnostics": {
              "description": "通过诊断代码来忽略ts报警",
              "items": {
                "type": [
                  "string",
                  "number"
                ]
              },
              "type": "array"
            },
            "logError": {
              "default": false,
              "description": "打印ts错误到stderr而不是抛出错误",
              "type": "boolean"
            },
            "preferTsExts": {
              "default": false,
              "description": "根据扩展名重排文件, 优先ts",
              "type": "boolean"
            },
            "pretty": {
              "default": false,
              "description": "使用 pretty来作为诊断格式化",
              "type": "boolean"
            },
            "scope": {
              "default": false,
              "description": "在`cwd`内局部编译文件",
              "type": "boolean"
            },
            "skipIgnore": {
              "default": false,
              "description": "跳过忽略检查",
              "type": "boolean"
            },
            "transpileOnly": {
              "default": false,
              "description": "使用ts的更快的转译模块`transpileModule`.",
              "type": "boolean"
            },
            "typeCheck": {
              "default": true,
              "description": "**已废弃** 定义类型检查是否开启 (e.g. `transpileOnly == false`).",
              "type": "boolean"
            }
          },
          "type": "object"
        }
      }
    }
  },
  "type": "object",
  "allOf": [
    {
      "$ref": "#/definitions/compilerOptionsDefinition"
    },
    {
      "$ref": "#/definitions/compileOnSaveDefinition"
    },
    {
      "$ref": "#/definitions/typeAcquisitionDefinition"
    },
    {
      "$ref": "#/definitions/extendsDefinition"
    },
    {
      "$ref": "#/definitions/tsNodeDefinition"
    },
    {
      "anyOf": [
        {
          "$ref": "#/definitions/filesDefinition"
        },
        {
          "$ref": "#/definitions/excludeDefinition"
        },
        {
          "$ref": "#/definitions/includeDefinition"
        },
        {
          "$ref": "#/definitions/referencesDefinition"
        }
      ]
    }
  ]
}