Skip to content
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

Closed
leeoniya opened this issue Nov 23, 2020 · 5 comments
Closed

Typescript: Use const enums where possible #29293

leeoniya opened this issue Nov 23, 2020 · 5 comments
Labels
area/frontend stale Issue with no recent activity type/chore

Comments

@leeoniya
Copy link
Contributor

leeoniya commented Nov 23, 2020

What would you like to be added:

switch from using enum to const enum where possible:

https://www.typescriptlang.org/docs/handbook/enums.html#const-enums

Why is this needed:

there are currently 74 TypeScript enums 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 removing const from this demo:

https://www.typescriptlang.org/play?ts=4.0.5#code/KYDwDg9gTgLgBAYwgOwM72MgrgWzgMQgjgG8AoOSuADTgF44BWAGgqoE164A2VquAFpcA7KwC+ZMgBtg8EF0IQAdNQDcQA

@torkelo torkelo changed the title use const enums where possible Typescript: Use const enums where possible Nov 23, 2020
@torkelo
Copy link
Member

torkelo commented Nov 23, 2020

Should be possible for most enums, for some we do iterate over the keys

@leeoniya
Copy link
Contributor Author

babel blocker: babel/babel#8741

@leeoniya
Copy link
Contributor Author

leeoniya commented Dec 4, 2020

Copy link
Contributor

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!

@github-actions github-actions bot added the stale Issue with no recent activity label Jan 22, 2024
Copy link
Contributor

This issue has been automatically closed because it has not had any further activity in the last 30 days. Thank you for your contributions!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/frontend stale Issue with no recent activity type/chore
Projects
None yet
Development

No branches or pull requests

2 participants