问题
After eslint adds typescript check, there will be an error when the attribute variable in the class definition is Array.
this is my eslintrc.js
module.exports = {
root: true,
env: {
node: true
},
'extends': ['plugin:vue/essential', '@vue/standard'],
rules: {},
parserOptions: {
parser: '@typescript-eslint/parser',
project: "./tsconfig.json"
},
plugins: ['@typescript-eslint']
};
回答1:
Looking at the eslint repository on github, there have been lots of issues opened about the no-unused-vars
rule. Here is some examples:
https://github.com/typescript-eslint/typescript-eslint/issues/45
https://github.com/typescript-eslint/typescript-eslint/issues/111
https://github.com/typescript-eslint/typescript-eslint/issues/171
It's an ongoing problem. Hopefully we can expect this to be resolved soon.
Edit: James Middleton has the correct answer. The @typescript-eslint
scope now contains working linting rules. Disable no-unused-vars
and enable it with "@typescript-eslint/no-unused-vars": "error"
回答2:
The solution is to disable the native no-unused-vars
so that only the TS one is enabled. The former is likely to be enabled if you extend a config in ESLint. Add the rules below to your ESLint config.
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error"
}
回答3:
The pictures added to my questions can not be browsed. In order to facilitate other people to help answer the questions, add a screenshot of my code in the form of answers.
import {Route} from '@/app/router/Route';
class YabRouter {
public widthOutAuthRoutes: Route[] = [];
public systemConfigRoutes: Route[] = [];
public staticRoutes: Route[] = [];
public dynamicRoutes: Route[] = [];
回答4:
If someone are still having the issue, I add "extends": ["eslint:recommended", "plugin:react/recommended"],
on the .eslintrc.json file and the problem get solved.
来源:https://stackoverflow.com/questions/55280555/typescript-eslint-eslint-plugin-error-route-is-defined-but-never-used-no-un