TypeScript Version: 2.9.0-dev.20180420
Search Terms: discriminated generic enum switch
Code
enumMyEnum{ONE='one',TWO='two',}interfaceTypeMap{[MyEnum.ONE]: number;[MyEnum.TWO]: string;}functiondoAction<TextendsMyEnum>(type: T,value: TypeMap[T]): void{switch(type){caseMyEnum.ONE:
console.log('type:',type,', value:',value);break;caseMyEnum.TWO:
console.log('type:',type,', value:',value);break;default:
console.log('type:',type,', value:',value);break;}}Expected behavior: the types of type would correspond to MyEnum.ONE / MyEnum.TWO depending on the case, and thus value would also get the expected type.
Actual behavior:: type is still T extends MyEnum even within the discriminated switch statement.
Playground Link:TS Playground
TypeScript Version: 2.9.0-dev.20180420
Search Terms: discriminated generic enum switch
Code
Expected behavior: the types of
typewould correspond toMyEnum.ONE/MyEnum.TWOdepending on thecase, and thus value would also get the expected type.Actual behavior::
typeis stillT extends MyEnumeven within the discriminated switch statement.Playground Link:TS Playground