TypeScript · Senior · Question 67 of 75
Why can a let variable lose its narrowing inside a callback but a const keeps it?
- ✓Correct answer: A
letmay be reassigned before the callback runs, so TS can't trust the earlier check;constcan't change - 2Callbacks reset all types
- 3
constvariables are never narrowed
Explanation
Recent versions preserve narrowing for let in closures created after the last assignment, but copying into a const is the simple fix.