TypeScript · Junior · Question 55 of 75

Why can typeof value === 'object' be a trap when narrowing?

Explanation

Combine it with value !== null, or use Array.isArray for arrays. TypeScript reflects this by keeping null in the narrowed type.

Further reading

Problem with a question

TypeScript · Junior · question 55

Test yourself

Take the TypeScript · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz