"Index expression arguments in 'const' enums must be of type 'string'"
This error message is quite ambiguous:
Seems that it should be
"Index expression argument of 'const' enum must be a string literal"
Because the compiler does so:
if (isConstEnumObjectType(objectType) && node.argumentExpression && node.argumentExpression.kind !== SyntaxKind.StringLiteral) {
error(node.argumentExpression, Diagnostics.Index_expression_arguments_in_const_enums_must_be_of_type_string);
}
A PR would be appreciated
The message is now "A const enum member can only be accessed using a string literal.", looks good to me.
If somebody has the same problem, just try to remove 'const' and everything will just work.
Well it's not entirely true, you have to do something like:
enum MyEnum{
A, B, C
}
let index = 2;
// this is how you can get the value from the enum without haveing tslint error message.
(<any>MyEnum)[index]
Most helpful comment
If somebody has the same problem, just try to remove 'const' and everything will just work.
Well it's not entirely true, you have to do something like: