Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

300
Views
Remove a property using object destructuring, without eslint no-unused-vars error

Consider the following code where I create a "copy" of x with one of the properties removed, using destructuring:

const x = { a: 1, b: 2, c: 3};
const { a, ...x2} = x;
console.log(x);
console.log(x2);

If I do it like this, @typescript-eslint/no-unused-vars will consider it an error that a is not used.

How can I change the code to fix the error, without explicitly asking eslint to ignore the offending line, preferably still using the destructuring syntax? I.e. I really don't want to use delete, nor do I want to explicitly enumerate all other properties like const x2 = {b: x.b, c: x.c }.

Is there a fancy syntax or weird eslint rule to have my cake and eat it too?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

There is a newly added option named ignoreRestSiblings for that rule.

You could set it to true to ignore your case:

{ "ignoreRestSiblings": true }
about 4 years ago · Juan Pablo Isaza Report

0

I'm usually remove some props with this util:

const removeProperty = <Obj, Prop extends keyof Obj>(obj: Obj, prop: Prop) => {
  const { [prop]: _, ...rest } = obj;
  return rest
}

Please check if it works for your case.

The trick is that you use underscore _ for unused variables.

You can allow explicitly using of _ in eslint rules.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!