5 ms·
1. You can define enum like `const enum A {...}` and they will not have runtime representation.
by nidu 6y ago
1. You can define enum like `const enum A {...}` and they will not have runtime representation.
- XVincentX 6y agoCorrect, but that does not solve the other issues I pointed. Additionally, const enums DO NOT have an associated type. That is a problem in libraries, since users cannot reuse the type definition around (it back ports to a string or a number)
- Jasper_ 6y agoconst enum doesn't work when in transpileOnly mode (e.g. webpack, Parcel), and Babel treats "const enum" the same as "enum". I'd really love a non-broken const enum in TypeScript, though.
- XVincentX 6y agoI'd love to see them out of the language. I do not have evidence/document supporting this, but I think it was ultimately a failed attempt of copying the C# feature ignoring the fact that JavaScript works differently.