Switch statement over a union of literals is not exhaustive when checking against enum members #53736
Labels
Experience Enhancement
Noncontroversial enhancements
Help Wanted
You can do this
Suggestion
An idea for TypeScript
Milestone
Bug Report
The following switch-case is unexpectedly not exhaustive:
Because X.FOO and X.BAR are just strings under the hood, I would expect this to compile as exhaustive. It's doubly surprising because:
x
within each case branchconst XConst = { FOO: "foo", BAR: "bar" } as const
)🔎 Search Terms
switch union literals exhaustive enum
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
function
test
does not compile🙂 Expected behavior
Function
test
compilesThe text was updated successfully, but these errors were encountered: