Sometimes, we want to fix an enum type not defined at runtime with TypeScript.
In this article, we’ll look at how to fix an enum type not defined at runtime with TypeScript.
How to fix an enum type not defined at runtime with TypeScript?
To fix an enum type not defined at runtime with TypeScript, we can use the const or export keyword before the enum.
For instance, we write
const enum MyEnum {
One = "one",
Two = "two",
}
to create the MyEnum enum with the const keyword before it to keep it in the compiled JavaScript code as an object.
We can also write
export enum MyEnum {
One = "one",
Two = "two",
}
if we want to export the module and use it in another module.
Conclusion
To fix an enum type not defined at runtime with TypeScript, we can use the const or export keyword before the enum.