TypeScript Version: 83fe1ea
Search Terms: switch typeof narrowing narrows
Code
// @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).
TypeScript Version: 83fe1ea
Search Terms: switch typeof narrowing narrows
Code
Expected behavior:
Switching on
typeofshould narrow union members in addition to filtering.undefinedshould be filtered and{}should be narrowed tostring.undefinedshould be filtered and{}should be narrowed tonumber.Actual behavior:
Switching on
typeofonly filters unions.undefinedis filtered but{}is not narrowed.undefinedis filtered but{}is not narrowed.Playground Link: Link: N/A (Playground not on this version).