-
Notifications
You must be signed in to change notification settings - Fork 11.7k
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
Typescript: Use const enums where possible #29293
Comments
Should be possible for most enums, for some we do iterate over the keys |
babel blocker: babel/babel#8741 |
possible unblocker: https://github.com/dosentmatter/babel-plugin-const-enum |
This issue has been automatically marked as stale because it has not had activity in the last year. It will be closed in 30 days if no further activity occurs. Please feel free to leave a comment if you believe the issue is still relevant. Thank you for your contributions! |
This issue has been automatically closed because it has not had any further activity in the last 30 days. Thank you for your contributions! |
What would you like to be added:
switch from using
enum
toconst enum
where possible:https://www.typescriptlang.org/docs/handbook/enums.html#const-enums
Why is this needed:
there are currently 74 TypeScript
enum
s in the Grafana codebase:https://github.com/grafana/grafana/search?q=%22export+enum%22
each of these generates a JavaScript backing object that is then used to reference into. in the overwhelming majority of cases (where enums are static and do not need to be iterated), this is unecessary perf and byte overhead. the simple fix is to switch to using
const enum
, which compiles down to the final value. you can see the difference in the generated output by removingconst
from this demo:https://www.typescriptlang.org/play?ts=4.0.5#code/KYDwDg9gTgLgBAYwgOwM72MgrgWzgMQgjgG8AoOSuADTgF44BWAGgqoE164A2VquAFpcA7KwC+ZMgBtg8EF0IQAdNQDcQA
The text was updated successfully, but these errors were encountered: