Title: Allow "T extends enum" generic constraint · Issue #30611 · microsoft/TypeScript · GitHub
Open Graph Title: Allow "T extends enum" generic constraint · Issue #30611 · microsoft/TypeScript
X Title: Allow "T extends enum" generic constraint · Issue #30611 · microsoft/TypeScript
Description: TypeScript has a discrete enum type that allows various compile-time checks and constraints to be enforced when using such types. It would be extremely useful to allow generic constraints to be limited to enum types - currently the only ...
Open Graph Description: TypeScript has a discrete enum type that allows various compile-time checks and constraints to be enforced when using such types. It would be extremely useful to allow generic constraints to be lim...
X Description: TypeScript has a discrete enum type that allows various compile-time checks and constraints to be enforced when using such types. It would be extremely useful to allow generic constraints to be lim...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/30611
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Allow \"T extends enum\" generic constraint","articleBody":"TypeScript has a discrete `enum` type that allows various compile-time checks and constraints to be enforced when using such types. It would be extremely useful to allow generic constraints to be limited to enum types - currently the only way to do this is via `T extends string | number` which neither conveys the intent of the programmer, nor imposes the requisite type enforcement.\r\n\r\n```ts\r\nexport enum StandardSortOrder {\r\n Default,\r\n Most,\r\n Least\r\n}\r\n\r\nexport enum AlternativeSortOrder {\r\n Default,\r\n High,\r\n Medium,\r\n Low\r\n}\r\n\r\nexport interface IThingThatUsesASortOrder\u003cT extends enum> { // doesn't compile\r\n sortOrder: T;\r\n}\r\n```","author":{"url":"https://github.com/IanKemp","@type":"Person","name":"IanKemp"},"datePublished":"2019-03-27T08:41:01Z","url":"https://github.com/microsoft/TypeScript/issues/30611"}
| 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:edc7ac88-f8cb-7dc5-a71d-e51ee1bb9d79 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B42A:1AE20C:25B6D64:2FB4596:6B0187CB |
| html-safe-nonce | 3069069737f843f26a4ecd27486c1d3ff385f6048f4090b4e6d946009c4fd764 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNDJBOjFBRTIwQzoyNUI2RDY0OjJGQjQ1OTY6NkIwMTg3Q0IiLCJ2aXNpdG9yX2lkIjoiNjkzMDM5MTE5MTEwOTgzMTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 455c8b25bfcd8ce97cb269c6bafcc52a791e09d714abaaae8a7613c2e85c31c1 |
| hovercard-subject-tag | issue:425827913 |
| 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/30611/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d51a5524dbed4238c810d1efdbae1b7e9aec18348550e9513e5dcd5bbc5a2d5e/microsoft/TypeScript/issues/30611 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d51a5524dbed4238c810d1efdbae1b7e9aec18348550e9513e5dcd5bbc5a2d5e/microsoft/TypeScript/issues/30611 |
| og:image:alt | TypeScript has a discrete enum type that allows various compile-time checks and constraints to be enforced when using such types. It would be extremely useful to allow generic constraints to be lim... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | IanKemp |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width