Allow "T extends enum" generic constraint
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. ```ts export enum StandardSortOrder { Default, Most, Least } export enum AlternativeSortOrder { Default, High, Medium, Low } export interface IThingThatUsesASortOrder<T extends enum> { // doesn't compile sortOrder: T; } ```
Posted by IanKemp on Mar 27, 2019, 8:41 AM
Tags
Related issues
- struct's lifetime requirements can be bypassed via covariant field assignment
- Proposal to Reorganize the Moderation Team and Review Moderation Policies
- Progressive FPS degradation appears to be related to dota2.com — blocking the domain prevents the performance loss
- proposal: container/...: generic collection types
- Better Custom Endpoint BYOK
- A concrete policy for backward compatibility until Godot 5.0
Raise real-world problems, find people facing the same issue, and discuss solutions.4,000 issues0 comments
github (Other)
struct's lifetime requirements can be bypassed via covariant field assignment
Proposal to Reorganize the Moderation Team and Review Moderation Policies
Progressive FPS degradation appears to be related to dota2.com — blocking the domain prevents the performance loss
proposal: container/...: generic collection types
Better Custom Endpoint BYOK
A concrete policy for backward compatibility until Godot 5.0
New MTP models not supported
Tracking: 429 / Capacity Issues
Allow "T extends enum" generic constraint
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. ```ts export enum StandardSortOrder { Default, Most, Least } export enum AlternativeSortOrder { Default, High, Medium, Low } export interface IThingThatUsesASortOrder<T extends enum> { // doesn't compile sortOrder: T; } ```
Comments (0)
No comments yet. Start the discussion.