文件夹内的特定 tsconfig.json 规则
Specific tsconfig.json rules inside folder
如何在我的 Typescript 项目中使用内部 config.json
?
为清楚起见:
我有一个根 /config.json
如下:
{
"compilerOptions": {
"module": "commonjs",
"target": "es2017",
"inlineSourceMap": true,
"outDir": "./app/",
"lib": [
"es6"
],
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": "node",
"baseUrl": "./",
"noImplicitAny": true,
"skipLibCheck": true,
"paths": {
"*": [
"types/*"
]
}
},
"include": [
"./src/**/*.ts"
]
}
我想要 /innerFolder/config.json
具有以下内容:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"noImplicitReturns": true,
"noUnusedParameters": true,
"noUnusedLocals": true,
"strictNullChecks": true,
}
}
我这样做是因为我想重构团队的代码,但它很大,我不想一次更改所有文件。
我想逐个文件夹地进行操作,"lock" 文件夹进行更改。
根据文档,编译器查找父 tsconfig.json
,但不查找特定的 tsconfig.json
。
有办法做到吗?
在单个项目中,无法将不同的编译器选项应用于不同的文件。如果您的文件夹遵循简单的依赖结构,您可以将多个项目与 project references. Otherwise, you could write a script that runs tsc
on the entire project twice (once with the stricter options and once with the looser options) and combines the errors from the first run on innerFolder
and the errors from the second run on all other files; see 一起使用,以获得有关如何按文件名过滤错误的一些灵感。这对您的 IDE 没有帮助;在那里,您可能只需要使用更宽松的选项。
曾经我只需要严格检查的规则,我可以使用tslint
来实现它。
tslint
中的 extends
完全满足我的需要,它下降了,覆盖了内部目录中的规则。
TypeScript 2.1 added configuration inheritance 现在应该可以按照您使用的方式工作了。
应该够用了:
tsc -p tsconfig.test.json
并设置您的“测试”脚本以调用 tsc
的用法
另请参阅:
如何在我的 Typescript 项目中使用内部 config.json
?
为清楚起见:
我有一个根 /config.json
如下:
{
"compilerOptions": {
"module": "commonjs",
"target": "es2017",
"inlineSourceMap": true,
"outDir": "./app/",
"lib": [
"es6"
],
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": "node",
"baseUrl": "./",
"noImplicitAny": true,
"skipLibCheck": true,
"paths": {
"*": [
"types/*"
]
}
},
"include": [
"./src/**/*.ts"
]
}
我想要 /innerFolder/config.json
具有以下内容:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"noImplicitReturns": true,
"noUnusedParameters": true,
"noUnusedLocals": true,
"strictNullChecks": true,
}
}
我这样做是因为我想重构团队的代码,但它很大,我不想一次更改所有文件。
我想逐个文件夹地进行操作,"lock" 文件夹进行更改。
根据文档,编译器查找父 tsconfig.json
,但不查找特定的 tsconfig.json
。
有办法做到吗?
在单个项目中,无法将不同的编译器选项应用于不同的文件。如果您的文件夹遵循简单的依赖结构,您可以将多个项目与 project references. Otherwise, you could write a script that runs tsc
on the entire project twice (once with the stricter options and once with the looser options) and combines the errors from the first run on innerFolder
and the errors from the second run on all other files; see
曾经我只需要严格检查的规则,我可以使用tslint
来实现它。
tslint
中的 extends
完全满足我的需要,它下降了,覆盖了内部目录中的规则。
TypeScript 2.1 added configuration inheritance 现在应该可以按照您使用的方式工作了。
应该够用了:
tsc -p tsconfig.test.json
并设置您的“测试”脚本以调用 tsc
的用法另请参阅: