-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
Bug Report
π Search Terms
enum, declare enum, union enum
π Version & Regression Information
- This changed between versions 4.9 and 5.0
Noticed this change when testing the 5.0 beta, specifically in the wake of #50528.
β― Playground Link
Playground link with relevant code
π» Code
enum MyEnum { A, B, C }
let val1 = MyEnum.A;
// ^? MyEnum
val1 = MyEnum.B;
declare enum MyDeclaredEnum { A, B, C }
let val2 = MyDeclaredEnum.A;
// ^? MyDeclaredEnum.A
val2 = MyDeclaredEnum.B;
// ^ Type 'MyDeclaredEnum.B' is not assignable to type 'MyDeclaredEnum.A'.(2322)
π Actual behavior
Assigning a declared enum member to a variable with let
infers the type to be exactly the type of that specific enum member.
π Expected behavior
The declared enum assignment should be the same as the regular enum assignment, where the type is inferred as the enum itself (a union of all enum members).
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue