-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
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,
undefinedshould be filtered and{}should be narrowed tostring. - In the second clause,
undefinedshould be filtered and{}should be narrowed tonumber.
Actual behavior:
Switching on typeof only filters unions.
- In the first clause,
undefinedis filtered but{}is not narrowed. - In the second clause,
undefinedis filtered but{}is not narrowed.
Playground Link: Link: N/A (Playground not on this version).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue