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

143
Vistas
Array.find (and other similar methods) does not implicitly return `undefined`

Array.prototype.find must return T | undefined.

But for some reason in my (automatically generated NestJS) environment TypeScript implicitly has only T as the return type of such methods.

How should I make TypeScript automatically inferr that find must return T | undefined?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Take a look at strictNullChecks compiler option: https://www.typescriptlang.org/tsconfig#strictNullChecks

When strictNullChecks is false, null and undefined are effectively ignored by the language. This can lead to unexpected errors at runtime.

When strictNullChecks is true, null and undefined have their own distinct types and you’ll get a type error if you try to use them where a concrete value is expected.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Is this what you are looking for?

const task: Task | undefined = this.tasks.find((task) => task.id === id);
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