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
enumAnimal{DOG,// Add second member to avoid https://github.com/microsoft/TypeScript/issues/23572.CAT}constzoo: {animal: Animal}|undefined={animal: Animal.DOG}// OK.functionintermediateVariable(): Animal{constanimal=zoo?.animal??Animal.DOGswitch(animal){caseAnimal.DOG: returnAnimal.DOGcaseAnimal.CAT: returnAnimal.CAT}}// Error: Function lacks ending return statement and return type does not include 'undefined'.(2366)functionexpression(): Animal{switch(zoo?.animal??Animal.DOG){caseAnimal.DOG: returnAnimal.DOGcaseAnimal.CAT: returnAnimal.CAT}}
Expected behavior: Inferred type doesn't depend on intermediate state.
Actual behavior: Inferred type differs when an expression is switched on directly versus when the value is assigned to an untyped intermediate variable and then switched on.
This issue is an effect of switching to the control flow analyzer for exhaustiveness checking. We need to unconditionally include CFA nodes representing a missing default clauses in order for our analysis to be correct. Currently we only include such CFA nodes when the switch expression is a narrowing expression.
TypeScript Version: 3.7.0-beta
Search Terms: enum switch
Code
Expected behavior: Inferred type doesn't depend on intermediate state.
Actual behavior: Inferred type differs when an expression is switched on directly versus when the value is assigned to an untyped intermediate variable and then switched on.
Playground Link
Related Issues: #6155 #32905
The text was updated successfully, but these errors were encountered: