skip to Main Content

I get an eslint warning that comes from the @typescript-eslint plugin.

‘instance’ is declared but its value is never read. ts(6133)

VSCode suggested the following line as a Quick Fix:

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

However, adding this line makes no difference, see below:

enter image description here

Please note that I want to use an inline rule as shown here to disable the warning for one specific line only. I do not want to disable it for a whole file, nor disable it for the whole project.

PS: This is a fresh Vite project with TypeScript and React.

2

Answers


  1. What I would suggest is to add to your eslintrc file a following rule

    rules: {
        ...,
        '@typescript-eslint/no-unused-vars': [
          'error',
          { argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
        ],
    }
    

    With this you can get the rid of the error this way :

    const [_instance, setInstance] = useState(null)
    
    Login or Signup to reply.
  2. You can avoid the error by destructuring the second element from the array without assigning the first element to a variable:

    const [, setInstance] = useState<SwiperClass | null>(null);
    

    I’m not sure exactly why you cannot suppress the error, but it’s possible that you need to disable more than one rule. Possibly the built-in no-unused-vars rule applies here?

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

    Here’s an answer about the syntax for disabling multiple rules.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search