IssueRaiser

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

Raise real-world problems, find people facing the same issue, and discuss solutions.4,000 issues0 comments

github (Other)

Allow "T extends enum" generic constraint

IanKempMar 27, 2019, 8:41 AM

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.

Comment on this issue