Title: String enum by default · Issue #33015 · microsoft/TypeScript · GitHub
Open Graph Title: String enum by default · Issue #33015 · microsoft/TypeScript
X Title: String enum by default · Issue #33015 · microsoft/TypeScript
Description: Search Terms enum,string,string enum Suggestion I find myself often writing something like this: enum ButtonType { Primary = "Primary", Secondary = "Secondary", } I believe some simple syntactic sugar around the above code would slightly...
Open Graph Description: Search Terms enum,string,string enum Suggestion I find myself often writing something like this: enum ButtonType { Primary = "Primary", Secondary = "Secondary", } I believe some simple syntactic su...
X Description: Search Terms enum,string,string enum Suggestion I find myself often writing something like this: enum ButtonType { Primary = "Primary", Secondary = "Secondary", } I believe some...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/33015
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"String enum by default","articleBody":"## Search Terms\r\n\r\nenum,string,string enum\r\n\r\n## Suggestion\r\n\r\nI find myself often writing something like this:\r\n\r\n```typescript\r\nenum ButtonType {\r\n Primary = \"Primary\",\r\n Secondary = \"Secondary\",\r\n}\r\n```\r\n\r\nI believe some simple syntactic sugar around the above code would slightly boost productivity for those using TypeScript.\r\n\r\n## Use Cases\r\n\r\nFor my use cases, I write most enums in the above fashion. Aside from debugging, my most common case is generating HTML tag class names from an enum.\r\n\r\nTake the popular [classnames](https://github.com/JedWatson/classnames#dynamic-class-names-with-es2015) package from [Jed Watson](https://github.com/JedWatson). The documentation shows the following example:\r\n\r\n```javascript\r\nlet buttonType = 'primary';\r\nclassNames({ [`btn-${buttonType}`]: true });\r\n```\r\n\r\nIn TypeScript:\r\n\r\n```typescript\r\nenum ButtonType {\r\n Primary = \"Primary\",\r\n Secondary = \"Secondary\",\r\n}\r\nlet buttonType = ButtonType.Primary\r\nclassNames({ [`btn-${buttonType.toLowerCase()}`]: true });\r\n```\r\n\r\n## Examples\r\n\r\nI have no good ideas about what the syntax for this would look like. This suggestion comes purely from my experience programming in TypeScript and not from any principles (or lack thereof) of language design.\r\n\r\n## Checklist\r\n\r\nMy suggestion meets these guidelines:\r\n\r\n* [X] This wouldn't be a breaking change in existing TypeScript/JavaScript code\r\n* [X] This wouldn't change the runtime behavior of existing JavaScript code\r\n* [-] This could be implemented without emitting different JS based on the types of the expressions. ***if opted in, the generated values would have strings(string enums)***\r\n* [-] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.) ***if opted in, the enum values would have strings(string enums)***\r\n* [X] This feature would agree with the rest of [TypeScript's Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals).\r\n\r\n","author":{"url":"https://github.com/geraldarthurdavis","@type":"Person","name":"geraldarthurdavis"},"datePublished":"2019-08-21T18:52:29Z","url":"https://github.com/microsoft/TypeScript/issues/33015"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f98d40c0-6fec-3d8c-d3b8-276916f238f6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C19A:395430:8FAEC8:C00BBB:6B00E1C8 |
| html-safe-nonce | 24b248179af5ce214701c75679b77d94e6ee95fe110e43986e47efe2b7a4c923 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMTlBOjM5NTQzMDo4RkFFQzg6QzAwQkJCOjZCMDBFMUM4IiwidmlzaXRvcl9pZCI6Ijg1NjMyNjgxNjQwNTY1NzIzNjEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5262c09e5f08ec2074f6a5606fe56f12d9d4a06d9a1ebaf24e77b058b59286ed |
| hovercard-subject-tag | issue:483593426 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/33015/issue_layout |
| twitter:image | https://opengraph.githubassets.com/af32699ffbab5d816e1ceea8047e43ec74d469bff0b4090a8ebced449cc77791/microsoft/TypeScript/issues/33015 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/af32699ffbab5d816e1ceea8047e43ec74d469bff0b4090a8ebced449cc77791/microsoft/TypeScript/issues/33015 |
| og:image:alt | Search Terms enum,string,string enum Suggestion I find myself often writing something like this: enum ButtonType { Primary = "Primary", Secondary = "Secondary", } I believe some simple syntactic su... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | geraldarthurdavis |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width