Add a generic utility type InferEnum to facilitate type inference for enums defined with pgEnum. This enhancement aligns with the existing InferSelectModel and InferInsertModel utilities, simplifying type definitions for enums in Drizzle ORM.
Proposed Changes
Addition of the InferEnum type: A generic type that infers the possible values of an enum defined with pgEnum.
This does not affect the existing functionality of the ORM. It merely adds a new utility type that developers can choose to use.
export type InferEnum<T> = T extends { enumValues: readonly (infer U)[] }
? U
: never;
Usage
Example before the change:
const status = pgEnum("status", ["pending", "completed", "cancelled"]);
type Status = (typeof status.enumValues)[number];
Example after the change:
const status = pgEnum("status", ["pending", "completed", "cancelled"]);
type Status = InferEnum<typeof status>;
Benefits
Simplifies and improves code readability when defining enum types.
Add a generic utility type
InferEnum
to facilitate type inference for enums defined withpgEnum
. This enhancement aligns with the existingInferSelectModel
andInferInsertModel
utilities, simplifying type definitions for enums in Drizzle ORM.Proposed Changes
Addition of the
InferEnum
type: A generic type that infers the possible values of an enum defined withpgEnum
. This does not affect the existing functionality of the ORM. It merely adds a new utility type that developers can choose to use.Usage
Example before the change:
Example after the change:
Benefits