Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: fix TypeBox/Zod numberic type generation #2808

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

edgesite
Copy link

Fix #2524

Before this patch:

type StringLike = string & { _: never };

export const enum1 = pgEnum('enum1', ['A' as StringLike, 'B' as StringLike]);
export const enum2 = pgEnum('enum2', ['A', 'B']);

export const table = pgTable('table', {
  number: integer('a_number'),
  string: text('a_string'),
  enum1: enum1('enum1'),
  enum2: enum2('enum2'),
});

type T = typeof table;
// type T_number = TUnion<[TLiteral<string>]>
type T_number = GetTypeboxType<T['number']>;
// type T_string = TString
type T_string = GetTypeboxType<T['string']>;
// type T_enum1 = TUnion<[TLiteral<StringLike>, TLiteral<StringLike>]>
type T_enum1 = GetTypeboxType<T['enum1']>;
// type T_enum2 = TUnion<[TLiteral<"A">, TLiteral<"B">]>
type T_enum2 = GetTypeboxType<T['enum2']>;

After this patch:

type StringLike = string & { _: never };

export const enum1 = pgEnum('enum1', ['A' as StringLike, 'B' as StringLike]);
export const enum2 = pgEnum('enum2', ['A', 'B']);

export const table = pgTable('table', {
  number: integer('a_number'),
  string: text('a_string'),
  enum1: enum1('enum1'),
  enum2: enum2('enum2'),
});

type T = typeof table;
// type T_number = TNumber
type T_number = GetTypeboxType<T['number']>;
// type T_string = TString
type T_string = GetTypeboxType<T['string']>;
// type T_enum1 = TUnion<[TLiteral<StringLike>, TLiteral<StringLike>]>
type T_enum1 = GetTypeboxType<T['enum1']>;
// type T_enum2 = TUnion<[TLiteral<"A">, TLiteral<"B">]>
type T_enum2 = GetTypeboxType<T['enum2']>;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG]: Drizzle-typebox types SQLite real field to string
1 participant