-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discriminated switch on generic enum type not inferring correct type #23578
Comments
Related (I think): #21483 |
|
Thanks for getting back, that does make sense. How would you rewrite the code to support this scenario, though? I tried something like this:
but of course, in this case |
The generic type is the correct way to do it.. the type really should be |
As a workaround, the following seems to now work with 3.3 (referring to the original): function doAction<T extends MyEnum>(type: T & MyEnum, value: TypeMap[T]): void { The type within a switch case gets narrowed down to something like |
Tracking at #22348 |
TypeScript Version: 2.9.0-dev.20180420
Search Terms: discriminated generic enum switch
Code
Expected behavior: the types of
type
would correspond toMyEnum.ONE
/MyEnum.TWO
depending on thecase
, and thus value would also get the expected type.Actual behavior::
type
is stillT extends MyEnum
even within the discriminated switch statement.Playground Link: TS Playground
The text was updated successfully, but these errors were encountered: