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
{{ message }}
Repository navigation
narrowing doesn't work for literal strings in switch when united with unconstrained string #10417
example1: DB guys introduced a new possible value to a set of well-known values, without letting anyone know, this new case has to be treated separately as a failure/default case/you name it
example2: this one is lengthy, gradual open-ended narrowing via composing resolving functions
SomeStuff is a union of One and Another why not to take advantage of their resolver functions
This is working as intended, so I'm changing the label to a suggestion. We currently only narrow in a switch statement when the type of the switch expression is a union of unit types. In your example, there's really no difference between the type string and string | 'a' | 'b'.
Activity
RyanCavanaugh commentedon Aug 18, 2016
Side question: what was your intent declaring something
string | 'a' | 'b'?zpdDG4gta8XKpMCd commentedon Aug 18, 2016
example1: DB guys introduced a new possible value to a set of well-known values, without letting anyone know, this new case has to be treated separately as a failure/default case/you name it
example2: this one is lengthy, gradual open-ended narrowing via composing resolving functions
SomeStuffis a union ofOneandAnotherwhy not to take advantage of their resolver functionsahejlsberg commentedon Aug 18, 2016
This is working as intended, so I'm changing the label to a suggestion. We currently only narrow in a
switchstatement when the type of the switch expression is a union of unit types. In your example, there's really no difference between the typestringandstring | 'a' | 'b'.zpdDG4gta8XKpMCd commentedon Aug 19, 2016
fyi, there is a workaround using
T extends stringrather than plainstringRyanCavanaugh commentedon Aug 19, 2016
Anders Hejlsberg (@ahejlsberg) why wouldn't we narrow whenever a literal value matches a literal in a union?