11

I am currently getting a eslint warning on function parameters within Types or Interfaces.

Doing the following:

type Test = {
  fn: (param: string) => void
}

Results in the following warning:

'param' is defined but never used. Allowed unused args must match /^_/u.

Here's what my .eslintrc.json looks like:

{
  "root": true,
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": "tsconfig.json"
  },
  "env": {
    "node": true
  },
  "plugins": ["@typescript-eslint"],
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:prettier/recommended"
  ],
  "rules": {
    "@typescript-eslint/interface-name-prefix": "off",
    "@typescript-eslint/explicit-function-return-type": "off",
    "@typescript-eslint/explicit-module-boundary-types": "off"
  }
}

Package versions:

"eslint": "^7.23.0"
"@typescript-eslint/eslint-plugin": "^4.22.1"
"@typescript-eslint/parser": "^4.22.1"

Similar questions have been asked already here and here, but the provided answers do not seem to be doing it for me.

Any suggestions as to what could be happening?

Hansel
  • 1,568
  • 1
  • 15
  • 29
  • I might be wrong, but probably restart your IDE. Specially, with VSCode, I have seen stale errors until I restart the IDE. It may not help, but may worth a try after you have done this https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-vars.md#how-to-use – Nishant May 06 '21 at 03:10
  • @Nishant yeah I tried that but no luck :( – Hansel May 06 '21 at 11:26
  • Doing what's on the link just converts what I'm getting from a `warning` to an `error` – Hansel May 06 '21 at 12:39

3 Answers3

11

I've solved it this way, put these two lines in rules in the eslint configuration file.

"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["error"]
Elder Carvalho
  • 688
  • 4
  • 14
  • for more info see: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-vars.md – gnupa Aug 20 '21 at 11:14
2

Instead of setting the no-unused-vars globally in your eslint config, you could set it to the line by placing this comment just above it:

 // eslint-disable-next-line @typescript-eslint/no-unused-vars

or to the entire file, just add this comment on the top:

/* eslint-disable @typescript-eslint/no-unused-vars */
2

You can configure the no-unused-vars rule to ignore arguments named param by adding this line to your .eslintrc.json rules: "no-unused-vars": ["error", { "argsIgnorePattern": "params"}]. See the docs: https://eslint.org/docs/latest/rules/no-unused-vars#argsignorepattern

Luciano
  • 426
  • 2
  • 9
  • 19