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
enumMyEnum{A,B,C}letval1=MyEnum.A;// ^? MyEnumval1=MyEnum.B;declareenumMyDeclaredEnum{A,B,C}letval2=MyDeclaredEnum.A;// ^? MyDeclaredEnum.Aval2=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).
The text was updated successfully, but these errors were encountered:
In a declaration context (a declare declaration or in a .d.ts file), an enum member without an initializer is considered a computed enum member. Previously, such members caused an enum to become a non-union numeric enum type where there aren't distinct types for each member. For example, in
declareenumE{A,B,C}
the members would all have the same type E. Following #50528 we now create unique and opaque enum member types E.A, E.B, and E.C and consider E a union of those types. This is analogous to what happens when the members are initialized with literal values. However, we don't have "fresh" and "regular" forms of the unique enum member types, and therefore they don't widen. So, where E.A widens to E (which is the union E.A | E.B | E.C) when E.A is declared with a literal value, it doesn't when it is a computed member. Looks like we need to fix this by having "fresh" and "regular" forms of computed enum member types.
Bug Report
π Search Terms
enum, declare enum, union enum
π Version & Regression Information
Noticed this change when testing the 5.0 beta, specifically in the wake of #50528.
β― Playground Link
Playground link with relevant code
π» Code
π 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).
The text was updated successfully, but these errors were encountered: