You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
declarefunctiontakesNumber(value: number): void;functiontest(value: unknown){if(typeofvalue!=="number")return;takesNumber(value);// okvalue=1;// assign the same type!takesNumber(value);// error (value is unknown, although we narrowed it to number before)}
🙁 Actual behavior
value is unknown after the assignment
🙂 Expected behavior
value should still be number
The text was updated successfully, but these errors were encountered:
AlCalzone
changed the title
Comparison with enum loses type-narrowing from unknown to number
When a unknown variable is narrowed to a specific type, assigning another value with the same type resets the first back to unknownFeb 7, 2021
Bug Report
🔎 Search Terms
unknown, number, assign
🕗 Version & Regression Information
On the playground this behavior goes back to at least 3.3.3333
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
value is
unknown
after the assignment🙂 Expected behavior
value should still be
number
The text was updated successfully, but these errors were encountered: