I am getting the error/warning from ESLint that 'd' is declared but never used, however I need this type declaration in function parameter to avoid subsequent TypeScript errors. Is there a way of solving this problem/warning except changing the rules in .eslintrc.json file for no-unused-vars?
-
1You need to use the TypeScript version of the rule, ESLint's rules aren't aware of types: github.com/typescript-eslint/typescript-eslint/blob/master/…jonrsharpe– jonrsharpe2021年08月16日 12:34:17 +00:00Commented Aug 16, 2021 at 12:34
2 Answers 2
In your .eslintrc.json add "no-unused-vars": ["error", { "argsIgnorePattern": "^_" }] to "rules". Mine looks like this:
...
"rules": {
"no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
},
...
Now you should be able to add an underscore to the start of your variable declarations and it should avoid the error message.
Ex:
const myFunc = (c, b) => {} would be const myFunc = (_c, _b) => {}
You can also take a look ate argsignorepattern in the ESLint documentation.
I believe if you are using the typescript you might also have to add "@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }]"
5 Comments
"rules": {"no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],} ?"no-unused-vars": ["error", { "argsIgnorePattern": "^_" }]i think this is the shortest answer
//.eslintrc.json
...
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
},
...