【发布时间】:2020-03-03 20:21:31
【问题描述】:
寻求帮助,将 TypeScript 编译器报告的类型错误转换为 ESLint 的输出。库 typescript-eslint (https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/TYPED_LINTING.md) 让我觉得这应该是可能的。
文件结构
src/
... source files
tsconfig.json
test/
... testing files
.eslintrc.js
package.json
tsconfig.json (symlink to src/tsconfig.json)
.eslintrc.js
module.exports = {
'env': {
'jest': true,
'node': true,
},
'extends': [
'airbnb-typescript/base',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:jest/recommended',
],
'parser': '@typescript-eslint/parser',
'parserOptions': {
'project': ['./tsconfig.json'],
'tsconfigRootDir': __dirname,
},
'plugins': [
'@typescript-eslint',
'jest',
],
'root': true,
};
package.json
{
"name": "...",
"version": "...",
"description": "...",
"scripts": {},
"devDependencies": {
"@types/jest": "^25.1.3",
"@typescript-eslint/eslint-plugin": "^2.21.0",
"@typescript-eslint/parser": "^2.21.0",
"eslint": "^6.8.0",
"eslint-config-airbnb-typescript": "^7.0.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-jest": "^23.8.1",
"jest": "^25.1.0",
"nock": "^12.0.2",
"ts-jest": "^25.2.1"
},
"dependencies": {
"@types/node": "^13.7.7",
"aws-sdk": "^2.630.0",
"jsonschema": "^1.2.5",
"typescript": "^3.8.3"
}
}
ESLint 的输出是空的——没有错误——但是运行 TypeScript 编译器,构建项目时,报错很多;例如:
src/file.ts:xx:xx - error TS2339: Property 'body' does not exist on type 'object'.
src/file.ts:xx:xx - error TS2314: Generic type 'Promise<T>' requires 1 type argument(s).
src/filets:xx:xx - error TS7006: Parameter 'err' implicitly has an 'any' type.
我是在配置中遗漏了什么,还是在某些方面不合适?或者这实际上是不可能的?
我想通过 ESLint 获取错误报告,因为在我处理项目时,我的编辑器中显示了 linting 错误。我正在使用 Atom (https://atom.io/),但我也希望它适用于 VSCode,也可能适用于 VIM;团队成员喜欢不同的编辑器。
【问题讨论】:
-
我创建了一个 Git 存储库来说明我遇到的不一致问题,希望有人可以帮助我正确配置它。 github.com/kalisjoshua/eslint-typescript-type-warnings-example
标签: typescript eslint typechecking