0

I have found this issue over and over in Typescript but haven't been able to find a solution other than disabling the rule for the selected code.

Every time I declare a function with parameters in a Typescript Interface I get the no-unused-vars error on the parameter, see example below.

interface Template {
    template: Template;
    setTemplate: (template: Template) => void;
}

In this case, the setTemplate() function would throw an Eslint warning: 'template' is defined but never used: Eslint no-unused-vars

Does anyone know the Eslint rule or config required to avoid this, tired of adding // eslint-disable-next-line no-unused-vars.

Viswanatha Swamy
  • 699
  • 1
  • 10
  • 17
Vuk
  • 693
  • 4
  • 14
  • 1
    How is ESLint set up for your codebase? – jonrsharpe Jun 25 '21 at 13:46
  • It is quite a large file didn't want to post the whole thing but the relevant rule in my eslint config is: no-unused-vars: - warn – Vuk Jun 25 '21 at 13:48
  • We don't want that either! Give a [mre]. Have you read e.g. https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/docs/getting-started/linting/FAQ.md#i-am-using-a-rule-from-eslint-core-and-it-doesnt-work-correctly-with-typescript-code? – jonrsharpe Jun 25 '21 at 13:48
  • @T.J.Crowder yes, that's correct. The ESLint rule is broken for TS. There is a separate TS rules. Let me find it. – VLAZ Jun 25 '21 at 13:50
  • 1
    Got it. Check the dupe. You need @typescript-eslint and then disable the regular `no-unused-vars`, use the `@typescript-eslint/no-unused-vars` – VLAZ Jun 25 '21 at 13:51
  • Will have a look now, I am using the '@typescript-eslint' in my eslint config – Vuk Jun 25 '21 at 13:52
  • Disabling the rule seems to have solved it, thanks! – Vuk Jun 25 '21 at 13:53
  • Yes. For whatever reason the plain ESLint rule `no-unused-vars` just doesn't work. AFAIK, you **have to** disable it. I think it's just that one, anything else is compatible with TS. – VLAZ Jun 25 '21 at 14:10

0 Answers0