@typescript-eslint/no-unused-vars.有一个问题所以,我们有类型
type SomeType = (name: string) => void;我们在字符串中有@typescript-eslint/no-unused-vars错误和类型声明,表示“名称”是定义的,但从未使用过。
类型使用示例:
export const LogSomeInfo: SomeType = (name: string) => {
const a = name;
console.log(a);
};或者:
interface CheckboxPropsType {
value: string,
onClick(value: string): void
}在onClick的时候.字符串,表示该值已定义,但从未使用。即使类型分配正确和实际的onClick处理程序使用的值!
问:这条规则有什么问题,为什么会在这种情况下触发。为什么eslint将类型/接口中的函数的类型声明识别为常规函数?我的eslint配置有问题吗?
"@typescript-eslint/eslint-plugin":"^3.6.1",“@-eslint/解析器”:"^4.0.1",“eslint airbnb-typescript”:"^9.0.0",
{
"extends": [
"airbnb-typescript",
"airbnb/hooks",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module",
"project": "./tsconfig.json"
},
"settings": {
"react": {
"version": "detect"
}
},
"plugins": ["@typescript-eslint", "react-hooks", "react"],
"env": {
"browser": true
},
"rules": {
"object-curly-newline": 0,
"import/named": ["error"],
"indent": ["error", 4],
"react/jsx-indent": ["error", 4],
"comma-dangle": ["error", "never"],
"import/prefer-default-export": "off",
"react/jsx-fragments": "off",
"arrow-body-style": "off",
"object-curly-spacing": "off",
"@typescript-eslint/indent": ["error", 4, {"SwitchCase": 1}],
"@typescript-eslint/explicit-module-boundary-types": "off",
"no-undef": "error",
"react/jsx-indent-props": ["error", 4],
"max-len": ["error", { "code": 120 }],
"react/prop-types": "off"
}
}发布于 2020-09-06 18:11:39
前面问过的类似问题:Why ESLint throws 'no-unused-vars' for TypeScript interface?
禁用'@typescript-eslint/no-unused-vars': 0规则,而在tsconfig.json中使用"strict": true、"noUnusedLocals": true和"noUnusedParameters": true
发布于 2020-09-08 17:10:01
资料来源:我是typescript-eslint项目的维护者。
如果将@typescript-eslint/parser和@typescript-eslint/eslint-plugin的版本更新为v4.1.0,则可以使用最新的更改,使@typescript-eslint/no-unused-vars在所有情况下都能正常工作。
顺便说一句,使用插件的v3.x,但是解析器的v4.x将使您处于一个非常奇怪的状态,没有定义和不受支持的行为。
您应该确保始终使用两个包的相同版本,因为每个版本都是一起发布的。
发布于 2022-05-10 07:18:16
只需确保您有以下最新版本:
在.eslintrc.js中,确保将下列行添加到rules部分:
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["error"]https://stackoverflow.com/questions/63767199
复制相似问题