Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

303
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda