跳转到内容

TypeScript配置

本文将介绍 ts.config.json中的配置项

compilerOptions

Type Checking

配置项介绍
strictboolean严格模式
noImplicitAnyboolean是否校验没有赋予类型的变量, 默认启用 any
strictNullChecksboolean是否进行严格的 null 检测
strictFunctionTypesboolean支持双向协变 (让参数可以进行协变操作)
strictBindCallApplyboolean保证调用函数的时候, 参数是统一的
strictPropertyInitializationboolean类中的属性进行属性的初始化才能使用
noImplicitThisboolean需要避免this 是 any
useUnknownInCatchVariablesbooleancatch 中的 error 类型是 unkown 不再是 any
alwaysStrictboolean永远打包的结构是严格模式
noUnusedLocalsboolean如果变量未被使用, 会发生警告
noUnusedParametersboolean如果参数未被使用, 会发生警告
exactOptionalPropertyTypesboolean类型中可选属性要传递 undefined
noImplicitReturnsboolean返回值是否每条路径都有
noFallthroughCasesInSwitchboolean防止 switch case 缺少 break 语句
noUncheckedIndexedAccessboolean通过索引访问必须添加一个 undefined 类型
noImplicitOverrideboolean重写前必须加 override
noPropertyAccessFromIndexSignatureboolean只能通过 [] 访问属性
allowUnusedLabelsboolean循环的 label 未使用时警告
allowUnreachableCodeboolean代码未触达时警告

Completeness

配置项介绍
skipDefaultLibCheckboolean是否检测 .d.ts文件
skipLibCheckboolean是否检测第三方库

Projects

配置项介绍
incrementalboolean增量编译 (配置文件热更新)
compositeboolean复合项目
tsBuildInfoFilestring增量文件编译的路径
disableSourceOfProjectReferenceRedirectboolean复合项目时 引用选用的是源文件 而不是声明文件
disableSolutionSearchingboolean引用其他项目时是否检测引用的项目
disableReferencedProjectLoadboolean禁用引用项目的加载

Type Acquisition

配置项介绍
referencesboolean引用其他的项目
includestring[]目标文件
excludestring[]排除文件