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

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

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 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