ESLint un-used varialbes rule for parameters of function type in TypeScript

Viewed 1445

I'm using ESLint with TypeScript. When I try to create a function type with some required parameters, ESLint shows error eslint: no-unused-vars.

type Func = (paramA: number) => void Here, paramA is un-used variable according to ESLint.

My .eslintrc.json file

{
    "env": {
        "browser": true,
        "es6": true
    },
    "extends": [
        "eslint:recommended",
        "plugin:@typescript-eslint/eslint-recommended"
    ],
    "globals": {
        "Atomics": "readonly",
        "SharedArrayBuffer": "readonly"
    },
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "ecmaVersion": 2018,
        "sourceType": "module"
    },
    "plugins": [
        "react",
        "@typescript-eslint"
    ],
    "rules": {
    }
}

So, what is then, the correct way to create a function type in TypeScript with ESLint?

Thanks in advance

3 Answers

As mentioned in the document of typescript-eslint, disabled the rule from eslint and enable from typescript-eslint.

{
  // note you must disable the base rule as it can report incorrect errors
  "no-unused-vars": "off",
  "@typescript-eslint/no-unused-vars": ["error"]
}

Actually, they have answered to this question in their FAQ

I needed to turn off eslint's, no-unused-vars rule, and turn on the typescript-eslint rule.

"rules": {
  "no-unused-vars": "off",
  "@typescript-eslint/no-unused-vars": "error"
}

If I understood you correctly, what you're trying to do is

const func: (paramA: number) => void

to define a function type.

Related