Home > OS >  Typescript ESlint: unused var error when using callback function with parameters
Typescript ESlint: unused var error when using callback function with parameters

Time:11-05

I have a situation, demo code below:

       const callFnWithArgs = (callback: (a: string, b: number) => void) =>
       async (a: string, b: number): Promise<void> => {
          try { 
               await callback(a,b)
              }
        catch(e){
            console.log(e)
        }

The code works fine, but I have ESLint unused vars property setup in the project. I receive error that a and b are unused-vars in line 1.

Any solution for this? Function signature changes are welcome.

Note:

  1. I do not wish to disable/bypass the unused vars property globally or here.
  2. I do not wish to use 'any'
  3. I do not wish to remove the type so that it would infer 'any'

CodePudding user response:

try checking the following discussions ESLint - Configuring "no-unused-vars" for TypeScript

there might be some eslint configuration issues

CodePudding user response:

see 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"
  }
};

CodePudding user response:

You need to use @typescript-eslint/no-unused-vars instead of no-unused-vars.

If you need to override a config, here's how to do it !

"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "warn"
  • Related