Closed
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).