Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!