Closed
Description
Currently it is not possible to access const enum
member at runtime by using string or number indexer. This makes sense because by default the declarations for these enums are not emitted in the JS code.
However, we can use preserveConstEnums:true
compiler option to both emit the enum declaration in the JS and to have the enum usages still be converted to simple numbers.
As such, it would make sense that with preserveConstEnums:true
the enum members should be accessible at runtime as well.
const enum Foo {
foo1 = 1,
foo2 = 2
}
// both lines fail with:
// A const enum member can only be accessed using a string literal.
let fk: "foo1" | "foo2" = Foo[1];
let f = Foo[fk];