Sometimes, we want to fix the "A const enum member can only be accessed using a string literal." error with TypeScript.
In this article, we’ll look at how to fix the "A const enum member can only be accessed using a string literal." error with TypeScript.
How to fix the "A const enum member can only be accessed using a string literal." error with TypeScript?
To fix the "A const enum member can only be accessed using a string literal." error with TypeScript, we should remove const
before the enum definition.
For instance, instead of writing
const enum Snack {
Apple = 0,
Banana = 1,
Orange = 2,
Other = 3,
}
we write
enum Snack {
Apple = 0,
Banana = 1,
Orange = 2,
Other = 3,
}
Conclusion
To fix the "A const enum member can only be accessed using a string literal." error with TypeScript, we should remove const
before the enum definition.