我想在cmd中使用eslint来检查ts文件,但是无法获取我在IDE中得到的错误信息。
我在eslintrc.js中设置了@ typescript-eslint / parser。当我做错了一些命令时,在cmd中运行的eslint给了我一些TS错误。但是没有发现其他错误。
我有一个包含以下代码的ts文件:
interface Item {
name: string;
age: number;
}
const config: Array<Item> = [{
name: 'foo',
}]
所以,我在IDE中出现了一些错误:
Property 'age' is missing in type '{ name: string; age: number }' but required in type 'Item'.ts(2741)
那是正确的。我需要此错误信息。
但是当我在cmd中运行eslint
eslint fileName.ts or eslint --ext .ts fileName.ts
cmd eslint在此文件中不返回任何内容或其他警告/错误。
此处为eslintrc
module.exports = {
"extends": ["xxx"],
"globals": {
"__SERVER_ENV__": true,
},
"rules": {
"react/jsx-filename-extension": 0,
"no-console": ["warn", { allow: ["error", "warn"] }],
"@typescript-eslint/no-unused-vars": ["error", {
"vars": "all",
"args": "after-used",
"ignoreRestSiblings": true
}],
},
"settings": {
"react": {
"createClass": "createReactClass", // Regex for Component Factory to use,
// default to "createReactClass"
"pragma": "React", // Pragma to use, default to "React"
"version": "detect", // React version. "detect" automatically picks the version you have installed.
// You can also use `16.0`, `16.3`, etc, if you want to override the detected value.
// default to latest and warns if missing
// It will default to "detect" in the future
},
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"]
},
"import/resolver": {
// use <root>/tsconfig.json
"typescript": {
// always try to resolve types under `<roo/>@types` directory even it doesn't contain any source code, like`@types/unist`
"alwaysTryTypes": true,
"directory": "./",
},
},
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"modules": true,
},
},
"plugins": ["@typescript-eslint", "import"],
};
和tsconfig.json
{
"compilerOptions": {
"experimentalDecorators": true,
"noImplicitAny": true,
"module": "commonjs",
"lib": ["es6","dom","es2017"],
"target": "es5",
"jsx": "react",
"types":["react"],
"outDir": "/output",
"baseUrl": ".",
"paths": {
"src/*": ["./src/*"]
},
"allowSyntheticDefaultImports": true,
"sourceMap": true
},
"awesomeTypescriptLoaderOptions": {
"useWebpackText": true,
"useTranspileModule": true,
"doTypeCheck": true,
"forkChecker": true
},
"include": [
".d.ts",
"./src/**/*"
]
}
我希望通过cmd获取全部错误信息。我该怎么办?
答案 0 :(得分:0)
似乎eslint设计不会执行您的Typescript类型检查。我只是使用tsc
在本地运行构建命令,以通知该“类型缺失的属性”错误消息,并在构建失败时进行修复。
这非常不方便,因为每次构建尝试只会收到一个错误的警报。如果有人有更好的解决方案,我将不胜感激。