-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Why does TypeScript PM advice not to use const enum? If so, why not take out from language SPEC #30590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Mistakes were made, depending on how you look at it. Wholesale cutting features out of the language is not something we do. |
Is there any improvement that could be made to https://www.typescriptlang.org/docs/handbook/enums.html to possibly steer new users away from or at least keep them mindful of the issues with const enum? |
@DanielRosenwasser didn't say don't use const enums, just use them appropriately. The problem is that it causes the TypeScript compiler to "hard code" all the values, fully erasing the I think @nattthebear's suggestion is a good one, though the handbook basically says "use regular enums unless..." already:
And it talks about how they are fully erased. I guess the only thing it doesn't say is they should be limited in use to "internal" enums. |
P.S. I have a name. |
Const enums are more performant and especially handy, as @kitsonk mentioned, for internal enums. I don't think mistakes were made. I am glad const enums are available. |
The feature definitely is useful, but the fact that Babel can't do this is part of what makes the design questionable. A better design in retrospect might have been a mode where |
@DanielRosenwasser That is a design flaw on the part of the library developer, not TypeScript. Allowing this feature also allows things like translating existing APIs which return numeric enums into TypeScript enums (which are more readable than checking if |
Why does TypeScript PM advice not to use const enum? If so, why not take out from language SPEC
facebook/create-react-app#4837 (comment)
The text was updated successfully, but these errors were encountered: