TypeScript · Junior · Question 55 of 75
Why can typeof value === 'object' be a trap when narrowing?
- ✓Correct answer: It's also true for
nulland arrays, sovaluemay still benull - 2It's always false in TypeScript
- 3It narrows to
any
Explanation
Combine it with value !== null, or use Array.isArray for arrays. TypeScript reflects this by keeping null in the narrowed type.