Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

302
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda