Search code examples
typescripteslinttypescript-eslint

typescript eslint rules. no-unused-vars#options for functions that return void


Consider this interface:

/*eslint no-unused-vars: ["warn", { "args": "after-used" }]*/
interface Whatever {
    x: number,
    y: number,
    myFunc: (arg1: number, arg2: string[]) => void // warning here
}

I get warnings:

1.- 'arg1' is defined but never used.eslintno-unused-vars
2.- 'arg2' is defined but never used.eslintno-unused-vars

I want my linter to check for variable usage in TS, but of course if function returns void, the variable wont be used in the type.

I'm surprised that that specific case cannot be arranged in the documentation. I mean the specific case of check the variable usage in the type, but not if the function returns void.


Solution

  • General principle:

    If some JS eslint rule conflicts with TS, disable JS rule
    

    In many cases TS rule may conflict with JS rule with same name

    https://typescript-eslint.io/rules/no-unused-vars/

    How to Use

    // .eslintrc.cjs
    module.exports = {
      "rules": {
        // Note: you must disable the base rule as it can report incorrect errors
        "no-unused-vars": "off",
        "@typescript-eslint/no-unused-vars": "warn"
      }
    };