Bug Report
π Search Terms
enum const initializer type
π Version & Regression Information
- I was unable to test this on prior versions because this feature is only supported starting from TS 5.0
β― Playground Link
Playground link with relevant code
π» Code
const Const1 = 10;
const enum Enum1 {
First = Const1,
Second
}
const Const2: 10 = 10;
const enum Enum2 {
First = Const2,
Second
}
const Const3 = 10 as const;
const enum Enum3 {
First = Const3,
Second
}
const Const4: number = 10;
const enum Enum4 {
First = Const4,
Second
}
π Actual behavior
The first enum is valid. For all the other ones, TS reports const enum member initializers must be constant expressions.
π Expected behavior
At least the second and third enums should be valid, because their initializer is a reference to a const variable with a fixed type. Maybe also the fourth one could work, but I wouldn't be surprised if it doesn't.
Bug Report
π Search Terms
enum const initializer type
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
The first enum is valid. For all the other ones, TS reports
const enum member initializers must be constant expressions.π Expected behavior
At least the second and third enums should be valid, because their initializer is a reference to a
constvariable with a fixed type. Maybe also the fourth one could work, but I wouldn't be surprised if it doesn't.