TypeScript · Middle · Question 75 of 75
What does switch (true) narrowing (TS 5.3) enable?
switch (true) {
case typeof x === 'string': return x.toUpperCase();
case Array.isArray(x): return x.length;
}- ✓Correct answer: Each
casecondition narrows the value inside that branch - 2It disables narrowing
- 3It requires an
enum
Explanation
It's a readable alternative to long if/else if chains with type guards.