30

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?

enter image description here

enter image description here

jonrsharpe
123k31 gold badges278 silver badges489 bronze badges
asked Aug 16, 2021 at 12:31
1

2 Answers 2

32

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": "^_" }]"

answered Aug 16, 2021 at 14:34
Sign up to request clarification or add additional context in comments.

5 Comments

Thank you a lot! Actually 'no-unused-vars': 1 just replaces the error with warning but following the link you mentioned and setting ["error", { "argsIgnorePattern": "^_" }] helped!
Glad I could help.
@spatak Did you just set "rules": {"no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],} ?
yes. I added it above all of my over rules
Great solution, I went with "no-unused-vars": ["error", { "argsIgnorePattern": "^_" }]
10

i think this is the shortest answer

//.eslintrc.json
...
"rules": {
 "no-unused-vars": "off",
 "@typescript-eslint/no-unused-vars": "error",
 },
...
answered Mar 28, 2022 at 1:10

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.