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

246
Visualizações
no-unsafe-optional-chaining does not work with "||" or condition

no-unsafe-optional-chaining is an amazing eslint rule, which help us identify why we are doing wrong with optional chaining..

I have one case where i need to perform a sort operation on id (in numbers) which could be in string type which make sense to throw error because the it could result in NaN if order is not a number

  const sortComparer = (a, b) => (+a?.order) - (+b?.order)

However, if i do handle no-unsafe-optional-chaining as follow it still throws error and does not work:

  const sortComparer = (a, b) => (+a.order || 0) - (+b.order || 0),

The only way to make it work is like this:

  const sortComparer = (a, b) => (a?.order ? +a.order : 0) - (b?.order ? +b.order : 0),

Does anyone know how to fix this in a better way to avoid this issue ?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This should work:

sortComparer: (a, b) => +(a?.order || 0) - +(b?.order || 0),

Move the + out of the (), and use the optional chaining to handle a or b being null.

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