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
// @strictNullChecks: truefunctionnarrowingNarrows(x: {}|undefined){switch(typeofx){case'string': x;return;// x is {}, should be stringcase'number': x;return;// x is {}, should be number}}
Expected behavior:
Switching on typeof should narrow union members in addition to filtering.
In the first clause, undefined should be filtered and {} should be narrowed to string.
In the second clause, undefined should be filtered and {} should be narrowed to number.
Actual behavior:
Switching on typeof only filters unions.
In the first clause, undefined is filtered but {} is not narrowed.
In the second clause, undefined is filtered but {} is not narrowed.
Playground Link: Link: N/A (Playground not on this version).
The text was updated successfully, but these errors were encountered:
The PR's in a milestone (even if not yet merged), so the fixed label is fine. It's good for making sure nobody else picks up the issue accidentally while it's still open.
TypeScript Version: 83fe1ea
Search Terms: switch typeof narrowing narrows
Code
Expected behavior:
Switching on
typeof
should narrow union members in addition to filtering.undefined
should be filtered and{}
should be narrowed tostring
.undefined
should be filtered and{}
should be narrowed tonumber
.Actual behavior:
Switching on
typeof
only filters unions.undefined
is filtered but{}
is not narrowed.undefined
is filtered but{}
is not narrowed.Playground Link: Link: N/A (Playground not on this version).
The text was updated successfully, but these errors were encountered: