TypeScript · Senior · Question 67 of 75

Why can a let variable lose its narrowing inside a callback but a const keeps it?

Explanation

Recent versions preserve narrowing for let in closures created after the last assignment, but copying into a const is the simple fix.

Further reading

Problem with a question

TypeScript · Senior · question 67

Test yourself

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

Take this quiz