Closed
Description
TypeScript Version: 83fe1ea
Search Terms: switch typeof narrowing narrows
Code
// @strictNullChecks: true
function narrowingNarrows(x: {} | undefined) {
switch (typeof x) {
case 'string': x; return; // x is {}, should be string
case '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 tostring
. - In the second clause,
undefined
should be filtered and{}
should be narrowed tonumber
.
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).