-
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: master 83fe1ea
Search Terms: switch typeof keyof intersection
Code
function keyofNarrowing<S extends { [K in keyof S]: string }>(k: keyof S) {
switch (typeof k) {
case 'number': k; return; // k has type number, should be keyof S & number
case 'symbol': k; return; // k has type number, should be keyof S & symbol
case 'string': k; return; // k has type number, should be keyof S & string
}
}Expected behavior:
The value k should narrow to an intersection type to retain keyof type.
Actual behavior:
The value k narrows to a primitive.
Playground 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