You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// A *self-contained* demonstration of the problem follows...enumTypes{A="A",B="B",}typeActionA={type:Types.A,id:number}typeActionB={type:Types.B,code:number}typeActions=ActionA|ActionBfunctionreturnActionCode(action:Actions){switch(action.type){caseTypes.A:
returnaction.iddefault:
action.code;}}// assigning a intermediate variable breaks the flow analysisfunctionreturnActionCodeFail(action:Actions){consttype=action.typeswitch(type){caseTypes.A:
returnaction.id// Property 'id' does not exist on type 'Actions'. Property 'id' does not exist on type 'ActionB'.default:
action.code;// Property 'code' does not exist on type 'Actions'. Property 'code' does not exist on type 'ActionA'.}}
Expected behavior:
Both functions should compile as they are equivalent
Actual behavior:
Only the first one is valid, Both are actually equal and should be valid, seems that having an intermediate variable assignment breaks the type inference. Playground Link: Playgorund Link Related Issues:
22093
The text was updated successfully, but these errors were encountered:
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
TypeScript Version: 2.8.3
Search Terms:
Variable Union
Code
Expected behavior:
Both functions should compile as they are equivalent
Actual behavior:
Only the first one is valid, Both are actually equal and should be valid, seems that having an intermediate variable assignment breaks the type inference.
Playground Link:
Playgorund Link
Related Issues:
22093
The text was updated successfully, but these errors were encountered: