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

232
Views
Why is a = null ?? [] of type never[]?

Why am I getting different type inference here for the array ?

const a = []; // any[]
const b = null ?? []; // never[] 

Demo here

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The "correct" thing to do would be to infer never[] for the empty array literal [], because the type of an array literal is the join of the types of its elements, and never is the join of an empty set.

However, since inferring never[] is usually not what the user intends when writing const a = [], this particular case received a very special treatment in the compiler, and now it starts by implicitly inferring any[], and then refining the type based on the subsequent control flow.

There does not seem to be any deeper meaning behind it: it's just what turns out to be the most useful in most cases.

over 4 years ago · Santiago Trujillo 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!