Quiz · 3 questions
🔎 Narrowing — How the Compiler Reads Your `if` Statements
typeof, instanceof, in, type predicates, control flow analysis
Level 0Curious
0 XP0/93 lessons0/23 achievements
0/100 XP to next level100 XP to go0% complete
Quiz
01What does
typeof x === 'string' do inside an if branch?Hint
Hover
x inside and outside the if to see the narrowed type.02When would you write a custom type predicate?
Hint
function isUser(x: unknown): x is User { return ... } — the x is User return type is what makes it a type predicate.03What is control flow analysis?
Hint
Try writing a function that early-returns on null, then accesses properties below — the compiler knows it's non-null below.
Comments 0
🔔 Reply notifications (sign in)Sign in — Please sign in to comment.
No comments yet — be the first.