Javascript: explictely ignore variables without esling warning about it

Javascript: explictely ignore variables without esling warning about it

Problem Description:

I have a code like this:

const [contract, _customer, _payment] = await Promise.all([
    api.signup.contract.sign(...),
    api.signup.update(...), 
    api.payment.update(...),
]);

And eslint is complaining because of

  118:15  warning  '_customer' is assigned a value but never used  @typescript-eslint/no-unused-vars
  118:26  warning  '_payment' is assigned a value but never used   @typescript-eslint/no-unused-vars

I though that prefixing the var with _ was enought to explicetly ignore the var (meaning it’s not a mistake)

What would be the best way avoid this issue?

Solution – 1

Making eslint ignore variables starting with an _ for the purposes of no-unused-vars tests is a configurable option:

no-unused-vars: ["error", { "argsIgnorePattern": "^_" }]

… however, in this case since you only use the first value, simply don’t destructure the second and third:

const [contract] = await Promise.all([ //...
Rate this post
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept
Reject