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]: Type error in drizzle-zod using Deno 2 #3426

Open
1 task done
eNiiju opened this issue Nov 5, 2024 · 0 comments
Open
1 task done

[BUG]: Type error in drizzle-zod using Deno 2 #3426

eNiiju opened this issue Nov 5, 2024 · 0 comments
Labels
bug Something isn't working drizzle/zod

Comments

@eNiiju
Copy link

eNiiju commented Nov 5, 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.0

What version of drizzle-kit are you using?

0.27.1

Other packages

[email protected]

Describe the Bug

Hello!

I am trying to generate zod schemas from postgres tables generated from drizzle-kit pull :

drizzle.config.ts:

export default defineConfig({
  out: "src/database/drizzle",
  dialect: "postgresql",
  schemaFilter: ["public", "auth"],
  dbCredentials: {
    url: databaseUrl,
  },
});

Example of table "todos" after running drizzle-kit pull:

export const todos = pgTable("todos", {
  id: text().notNull(),
  label: text().notNull(),
  done: boolean().default(false).notNull(),
  createdAt: timestamp("created_at", { withTimezone: true, mode: "string" })
    .defaultNow().notNull(),
  updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" })
    .defaultNow().notNull(),
  userId: text("user_id").notNull(),
}, (table) => {
  return {
    todosUserIdFkey: foreignKey({
      columns: [table.userId],
      foreignColumns: [usersInAuth.id],
      name: "todos_user_id_fkey",
    }).onDelete("cascade"),
  };
});

Trying to create zod schemas

import { createInsertSchema } from "drizzle-zod";

export const insertTodoSchema = createInsertSchema(todos);
export type CreateTodo = z.infer<typeof insertTodoSchema>;

I'm getting this type error :

Argument of type 'PgTableWithColumns<{ name: "todos"; schema: undefined; columns: { id: PgColumn<{ name: "id"; tableName: "todos"; dataType: "string"; columnType: "PgText"; data: string; driverParam: string; notNull: true; hasDefault: false; ... 5 more ...; generated: undefined; }, {}, {}>; ... 4 more ...; userId: PgColumn<...>; }; d...' is not assignable to parameter of type 'Table<TableConfig<Column<any, object, object>>>'.
  The types of '_.config.columns' are incompatible between these types.
    Type '{ id: PgColumn<{ name: "id"; tableName: "todos"; dataType: "string"; columnType: "PgText"; data: string; driverParam: string; notNull: true; hasDefault: false; isPrimaryKey: false; isAutoincrement: false; hasRuntimeDefault: false; enumValues: [...]; baseColumn: never; generated: undefined; }, {}, {}>; ... 4 more ......' is not assignable to type 'Record<string, Column<any, object, object>>'.
      Property 'id' is incompatible with index signature.
        Type 'PgColumn<{ name: "id"; tableName: "todos"; dataType: "string"; columnType: "PgText"; data: string; driverParam: string; notNull: true; hasDefault: false; isPrimaryKey: false; isAutoincrement: false; hasRuntimeDefault: false; enumValues: [...]; baseColumn: never; generated: undefined; }, {}, {}>' is not assignable to type 'Column<any, object, object>'.
          The types of 'table._.config.columns' are incompatible between these types.
            Type 'Record<string, PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}>>' is not assignable to type 'Record<string, Column<any, object, object>>'.
              'string' index signatures are incompatible.
                Type 'PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}>' is not assignable to type 'Column<any, object, object>'.
                  Property 'config' is protected but type 'Column<T, TRuntimeConfig, TTypeConfig>' is not a class derived from 'Column<T, TRuntimeConfig, TTypeConfig>'

And can't infer types to use in my application.

I am using Deno 2:

$ deno --version
deno 2.0.4 (stable, release, x86_64-pc-windows-msvc)
v8 12.9.202.13-rusty
typescript 5.6.2
@eNiiju eNiiju added the bug Something isn't working label Nov 5, 2024
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

2 participants