Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Javascript: explictely ignore variables without esling warning about it

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)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What would be the best way avoid this issue?

>Solution :

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([ //...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading