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

[BUG]: drizzle-zod Type generation results in undefined types #3645

Closed
1 task done
gregegan opened this issue Nov 29, 2024 · 4 comments
Closed
1 task done

[BUG]: drizzle-zod Type generation results in undefined types #3645

gregegan opened this issue Nov 29, 2024 · 4 comments
Labels
bug Something isn't working drizzle/zod

Comments

@gregegan
Copy link

gregegan commented Nov 29, 2024

Report hasn't been filed before.

  • I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

^0.36.4

What version of drizzle-kit are you using?

^0.28.1

Other packages

"drizzle-zod": "^0.5.1",

Describe the Bug

I am using drizzle-zod to generate types, as I want to use them on the frontend/client... so I am running tsc on them and exporting them.

The issue i'm facing is that any non-string is being generated as a undefined type, you can see in my final code snippet.

Any suggestions?

Here is my tsc command i'm running
tsc src/config/types.ts --declaration --emitDeclarationOnly --skipLibCheck --outDir dist/types/api

Here is the schema

export const competitions = pgTable('competitions', {
    id: uuid('id').primaryKey().defaultRandom(),
    title: text('title').notNull(),
    description: text('description').notNull(),
    entryCost: integer('entry_cost').notNull(),
    prizePool: integer('prize_pool').notNull(),  // Total points to distribute as rewards.
...

Here is the drizzle-zod schema

export type Competition = z.infer<typeof selectCompetitionSchema>;

Here is the generated tsc file

export declare const competitions: import("drizzle-orm/pg-core").PgTableWithColumns<{
    name: "competitions";
    schema: undefined;
    columns: {
        id: import("drizzle-orm/pg-core").PgColumn<{
            name: "id";
            tableName: "competitions";
            dataType: "string";
            columnType: "PgUUID";
            data: string;
            driverParam: string;
            notNull: true;
            hasDefault: true;
            isPrimaryKey: true;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        title: import("drizzle-orm/pg-core").PgColumn<{
            name: "title";
            tableName: "competitions";
            dataType: "string";
            columnType: "PgText";
            data: string;
            driverParam: string;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        description: import("drizzle-orm/pg-core").PgColumn<{
            name: "description";
            tableName: "competitions";
            dataType: "string";
            columnType: "PgText";
            data: string;
            driverParam: string;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        entryCost: import("drizzle-orm/pg-core").PgColumn<{
            name: "entry_cost";
            tableName: "competitions";
            dataType: "number";
            columnType: "PgInteger";
            data: number;
            driverParam: string | number;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        prizePool: import("drizzle-orm/pg-core").PgColumn<{
            name: "prize_pool";
            tableName: "competitions";
            dataType: "number";
            columnType: "PgInteger";
            data: number;
            driverParam: string | number;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;

As you can see here, all of the below types are coming back as undefined when they should be defined as numbers or strings

export declare const selectCompetitionSchema: z.ZodObject<{
    id: z.ZodEnum<undefined>;
    title: z.ZodString;
    description: z.ZodString;
    entryCost: z.ZodEnum<undefined>;
    prizePool: z.ZodEnum<undefined>;

...
@gregegan gregegan added the bug Something isn't working label Nov 29, 2024
@AndriiSherman
Copy link
Member

This one was fixed in the latest drizzle-zod@0.6.0

@gregegan
Copy link
Author

gregegan commented Dec 9, 2024

Thanks for looking into it @AndriiSherman. It looks like a new issue now with no exported modules on the schema.types.internal

Screenshot 2024-12-09 at 3 56 46 PM

@gregegan
Copy link
Author

gregegan commented Dec 9, 2024

Previous to this version it was generating this here

Screenshot 2024-12-09 at 3 58 56 PM

@bernardoforcillo
Copy link

Previous to this version it was generating this here

Screenshot 2024-12-09 at 3 58 56 PM

I'm incurring on the same problem, drizzle-zod is 0.6.1...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working drizzle/zod
Projects
None yet
Development

No branches or pull requests

4 participants