Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ESLint - "no-unused-vars" on function parameters within TypeScript Types/Interfaces

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?

like image 782
Hansel Avatar asked Sep 12 '25 10:09

Hansel


2 Answers

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"]
like image 131
Elder Carvalho Avatar answered Sep 15 '25 02:09

Elder Carvalho


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

like image 28
Luciano Avatar answered Sep 15 '25 04:09

Luciano