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
This is the behavior in every version I tried, and I reviewed the FAQ for entries about type discrimination & narrowing in switches.
crashes on 3.5.x and above. Before this I couldn't run the playground because as const wasn't available. However, similar behavior happens when using enums (will include 2nd playground)
This is working as intended: item is not of a discriminated union type (it's not of a union type at all), so checking item.kind only narrows the type of item.kind itself; it does not narrow the type of item. See #31755. There is also an open feature request at #42384 asking for this sort of behavior.
Bug Report
🔎 Search Terms
narrow switch, discriminate switch, refine switch
🕗 Version & Regression Information
crashes on 3.5.x and above. Before this I couldn't run the playground because
as const
wasn't available. However, similar behavior happens when using enums (will include 2nd playground)⏯ Playground Link
Playground link with relevant code using as const
Playground link with relevant code using enum
💻 Code
🙁 Actual behavior
Error on extractFoo & extractBar
🙂 Expected behavior
item
should be a valid parameter to extractFoo/extractBar because thekind
property should be narrowed/refined by the switch statement.The text was updated successfully, but these errors were encountered: