3

Without bypassing the warning no-unused-vars, how can I fix this code for ESLint to not complain about _?

I thought renaming the variable to _ would solve the issue.

type ById = (_: any) => string

export const normalize = (byId: ById) => (acc: Record<string, unknown>, doc: { data: () => unknown }) => ({
  ...acc,
  [byId(doc)]: doc.data(),
})
2:14  error  '_' is defined but never used       no-unused-vars
Rodrigo
  • 135
  • 4
  • 45
  • 107
  • 2
    It's an issue with ESLint parsing the TS type. The rule itself is broken for TS code. There is a replacement. Let me find it – VLAZ Jan 27 '21 at 15:24
  • 3
    wouldn't this fix it? https://eslint.org/docs/2.0.0/rules/no-unused-vars#ignore-identifiers-that-match-specific-patterns – Nishant Jan 27 '21 at 15:25
  • 3
    @Nishant it's a workaround. ESLint still parses and interprets the *type* as *a function* which is the core of the problem. – VLAZ Jan 27 '21 at 15:25
  • 4
    Does this answer your question? [esLint - Configuring "no-unused-vars" for Typescript](https://stackoverflow.com/questions/57802057/eslint-configuring-no-unused-vars-for-typescript) – VLAZ Jan 27 '21 at 15:26
  • 1
    @Nishant the workaround worked to me. Thanks! – Rodrigo Jan 27 '21 at 15:27
  • You need to install [this package](https://github.com/typescript-eslint/typescript-eslint) which extends the ESLint stuff and adds some TS specific rules. In particular, it has [`@typescript-eslint/no-unused-vars`](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-vars.md) which is the fixed rules you can use. – VLAZ Jan 27 '21 at 15:28
  • The link in Nishant's comment has rotted. Here is the Wayback Machine link: https://web.archive.org/web/20201112015712/https://eslint.org/docs/2.0.0/rules/no-unused-vars – Mike Airey Jul 03 '23 at 02:19

0 Answers0