Skip to content

Commit

Permalink
Merge pull request #417 from 0xOlias/kjs/fix-enum-type-infer
Browse files Browse the repository at this point in the history
Fix bug with inferring enum types
  • Loading branch information
kyscott18 authored Nov 10, 2023
2 parents 49fa33c + 583e066 commit 390c0f6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/schema/schema.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@ test("schema", () => {
type t = p.Infer<typeof s>;
// ^?

assertType<t>({} as { t: { id: string; e: ["ONE", "TWO"] } });
assertType<t>({} as { t: { id: string; e: "ONE" | "TWO" } });
});
7 changes: 6 additions & 1 deletion packages/core/src/schema/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,12 @@ export type RecoverEnumType<
| ReferenceColumn
| EnumColumn
| VirtualColumn
> = TColumn extends EnumColumn ? TEnums[TColumn["type"] & keyof TEnums] : never;
> = TColumn extends EnumColumn
? TEnums[TColumn["type"] &
keyof TEnums] extends infer _enum extends readonly string[]
? _enum[number]
: never
: never;

export type RecoverTableType<
TEnums extends Record<string, Enum>,
Expand Down

1 comment on commit 390c0f6

@vercel
Copy link

@vercel vercel bot commented on 390c0f6 Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.