转译时排除 *.spec.ts 文件但仍正确地对其进行 lint
Exclude *.spec.ts files when transpiling but still lint them properly
如何排除 typescript 文件被转译,但仍然确保它们在 Atom 编辑器中与 linter 一起正常工作?
我的 *.spec.ts
文件中出现此错误:
An async function or method in ES5/ES3 requires the 'Promise'
constructor. Make sure you have a declaration for the 'Promise'
constructor or include 'ES2015' in your --lib
option.
出现问题是因为我明确排除了包含我所有测试文件的目录(请参阅下面的 tsconfig 文件),因为我不希望这些文件在我构建时被转换为 JavaScript该项目。但是,当我在 Atom 编辑器中查看这些文件时,我确实希望这些文件能够被 tslint 插件正确检查。
我的设置:
- Atom.io 1.30 带插件:
- 原子打字稿 12.6.3
- 语言打字稿 0.4.0
- linter-tslint 1.9.1
- tslint 5.9.1
- 打字稿 3.0.1
我的 tsconfig.json
文件:
{
"compileOnSave": false,
"compilerOptions": {
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"baseUrl": ".",
"declaration": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"inlineSourceMap": true,
"inlineSources": true,
"lib": [
"es2017",
"dom"
],
"moduleResolution": "node",
"newLine": "lf",
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "./dist",
"target": "es5",
"typeRoots": [
"node_modules/@types"
]
},
"exclude": [
"./spec",
"./dist"
]
}
您需要使用两个 tsconfig.json
文件,一个用于编辑器(包括 *.spec.ts
文件),另一个用于编译(不包括它们)。您可以使用 extends
来共享两个文件之间的大部分选项。参见 。
如何排除 typescript 文件被转译,但仍然确保它们在 Atom 编辑器中与 linter 一起正常工作?
我的 *.spec.ts
文件中出现此错误:
An async function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your
--lib
option.
出现问题是因为我明确排除了包含我所有测试文件的目录(请参阅下面的 tsconfig 文件),因为我不希望这些文件在我构建时被转换为 JavaScript该项目。但是,当我在 Atom 编辑器中查看这些文件时,我确实希望这些文件能够被 tslint 插件正确检查。
我的设置:
- Atom.io 1.30 带插件:
- 原子打字稿 12.6.3
- 语言打字稿 0.4.0
- linter-tslint 1.9.1
- tslint 5.9.1
- 打字稿 3.0.1
我的 tsconfig.json
文件:
{
"compileOnSave": false,
"compilerOptions": {
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"baseUrl": ".",
"declaration": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"inlineSourceMap": true,
"inlineSources": true,
"lib": [
"es2017",
"dom"
],
"moduleResolution": "node",
"newLine": "lf",
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "./dist",
"target": "es5",
"typeRoots": [
"node_modules/@types"
]
},
"exclude": [
"./spec",
"./dist"
]
}
您需要使用两个 tsconfig.json
文件,一个用于编辑器(包括 *.spec.ts
文件),另一个用于编译(不包括它们)。您可以使用 extends
来共享两个文件之间的大部分选项。参见