Monorepo sharing schema problem

I have turborepo where I have two packages -> drizzle-schema and api-contracts so I try to import some table definitions from drizzle-schema module to api-contracts, which have drizzle-zod installed to generate zod schemas but when I import table definitions from drizzle-schema, and pass them to drizzle-zod functions, I get I type errors
No description
35 Replies
👾Rnbsov
👾RnbsovOP5mo ago
here is table definition for example
👾Rnbsov
👾RnbsovOP5mo ago
I import it in the another package, but getting a type error
No description
👾Rnbsov
👾RnbsovOP5mo ago
to debug this I installed drizzle-zod to drizzle-schema package, and tried to create a zod schema there everything worked fine
No description
👾Rnbsov
👾RnbsovOP5mo ago
No description
No description
No description
👾Rnbsov
👾RnbsovOP5mo ago
here is how I build types
👾Rnbsov
👾RnbsovOP5mo ago
No description
👾Rnbsov
👾RnbsovOP5mo ago
@⚡Z.E.U.S⚡ sorry for bothering sir, but can you give me suggestions please how to fix this
⚡Z.E.U.S⚡
⚡Z.E.U.S⚡5mo ago
Hey, @👾Rnbsov! Can you check that both packages have the same version of drizzle orm installed?
👾Rnbsov
👾RnbsovOP5mo ago
sure, I've installed the same versions in both one moment
👾Rnbsov
👾RnbsovOP5mo ago
No description
No description
👾Rnbsov
👾RnbsovOP5mo ago
No overload matches this call.
The last overload gave the following error.
Argument of type 'PgTableWithColumns<{ name: "events"; schema: undefined; columns: { id: PgColumn<{ name: "id"; tableName: "events"; dataType: "number"; columnType: "PgInteger"; data: number; driverParam: string | number; notNull: true; ... 7 more ...; generated: undefined; }, {}, {}>; ... 10 more ...; updatedAt: PgColumn<...>; }; di...' is not assignable to parameter of type 'PgEnum<any>'.
Type 'PgTable<{ name: "events"; schema: undefined; columns: { id: PgColumn<{ name: "id"; tableName: "events"; dataType: "number"; columnType: "PgInteger"; data: number; driverParam: string | number; notNull: true; ... 7 more ...; generated: undefined; }, {}, {}>; ... 10 more ...; updatedAt: PgColumn<...>; }; dialect: "pg"...' is missing the following properties from type 'PgEnum<any>': enumName, enumValues, schemats(2769)
schema.types.d.ts(10, 5): The last overload is declared here.
No overload matches this call.
The last overload gave the following error.
Argument of type 'PgTableWithColumns<{ name: "events"; schema: undefined; columns: { id: PgColumn<{ name: "id"; tableName: "events"; dataType: "number"; columnType: "PgInteger"; data: number; driverParam: string | number; notNull: true; ... 7 more ...; generated: undefined; }, {}, {}>; ... 10 more ...; updatedAt: PgColumn<...>; }; di...' is not assignable to parameter of type 'PgEnum<any>'.
Type 'PgTable<{ name: "events"; schema: undefined; columns: { id: PgColumn<{ name: "id"; tableName: "events"; dataType: "number"; columnType: "PgInteger"; data: number; driverParam: string | number; notNull: true; ... 7 more ...; generated: undefined; }, {}, {}>; ... 10 more ...; updatedAt: PgColumn<...>; }; dialect: "pg"...' is missing the following properties from type 'PgEnum<any>': enumName, enumValues, schemats(2769)
schema.types.d.ts(10, 5): The last overload is declared here.
No description
👾Rnbsov
👾RnbsovOP5mo ago
current type issue seems to be smaller
⚡Z.E.U.S⚡
⚡Z.E.U.S⚡5mo ago
Can you try to delete all node_modules and reinstall?
👾Rnbsov
👾RnbsovOP5mo ago
okay same issue
Ling Mai Jiānguǒ
try installing drizzle-orm@latest, drizzle-zod@latest, then make sure versions are consistent across the application
👾Rnbsov
👾RnbsovOP5mo ago
I'm getting so many problems with drizzle-zod ugh I've already decided to declare zod schemas (insert, select, update) in drizzle-schema package
👾Rnbsov
👾RnbsovOP5mo ago
though I still experience problems
No description
👾Rnbsov
👾RnbsovOP5mo ago
Argument of type 'BuildSchema<"select", { id: PgColumn<{ name: "id"; tableName: "tags"; dataType: "number"; columnType: "PgInteger"; data: number; driverParam: string | number; notNull: true; hasDefault: true; isPrimaryKey: true; ... 5 more ...; generated: undefined; }, {}, {}>; name: PgColumn<...>; createdAt: PgColumn<...>; updatedA...' is not assignable to parameter of type 'ZodTypeAny'.
Type 'ZodObject<{ id: ZodType<Buffer, unknown>; name: ZodType<Buffer, unknown>; createdAt: ZodNullable<ZodDate>; updatedAt: ZodNullable<ZodDate>; }, { out: {}; in: {}; }>' is missing the following properties from type 'ZodType<any, any, any>': _type, _parse, _getType, _getOrReturnCtx, and 7 more.ts(2345)
Argument of type 'BuildSchema<"select", { id: PgColumn<{ name: "id"; tableName: "tags"; dataType: "number"; columnType: "PgInteger"; data: number; driverParam: string | number; notNull: true; hasDefault: true; isPrimaryKey: true; ... 5 more ...; generated: undefined; }, {}, {}>; name: PgColumn<...>; createdAt: PgColumn<...>; updatedA...' is not assignable to parameter of type 'ZodTypeAny'.
Type 'ZodObject<{ id: ZodType<Buffer, unknown>; name: ZodType<Buffer, unknown>; createdAt: ZodNullable<ZodDate>; updatedAt: ZodNullable<ZodDate>; }, { out: {}; in: {}; }>' is missing the following properties from type 'ZodType<any, any, any>': _type, _parse, _getType, _getOrReturnCtx, and 7 more.ts(2345)
👾Rnbsov
👾RnbsovOP5mo ago
No description
👾Rnbsov
👾RnbsovOP5mo ago
@Ling Mai Jiānguǒ What are the chanches that updating drizzle-orm (drizzle-zod is already at latest) to latest will solve the issues? giving a try to this one
👾Rnbsov
👾RnbsovOP5mo ago
updated
No description
👾Rnbsov
👾RnbsovOP5mo ago
same issue persistes
No description
👾Rnbsov
👾RnbsovOP5mo ago
Argument of type 'BuildSchema<"select", { id: PgColumn<{ name: "id"; tableName: "tags"; dataType: "number"; columnType: "PgInteger"; data: number; driverParam: string | number; notNull: true; hasDefault: true; isPrimaryKey: true; ... 5 more ...; generated: undefined; }, {}, {}>; name: PgColumn<...>; createdAt: PgColumn<...>; updatedA...' is not assignable to parameter of type 'ZodTypeAny'.
Type 'ZodObject<{ id: ZodType<Buffer, unknown>; name: ZodType<Buffer, unknown>; createdAt: ZodNullable<ZodDate>; updatedAt: ZodNullable<ZodDate>; }, { out: {}; in: {}; }>' is missing the following properties from type 'ZodType<any, any, any>': _type, _parse, _getType, _getOrReturnCtx, and 7 more.ts(2345)
Argument of type 'BuildSchema<"select", { id: PgColumn<{ name: "id"; tableName: "tags"; dataType: "number"; columnType: "PgInteger"; data: number; driverParam: string | number; notNull: true; hasDefault: true; isPrimaryKey: true; ... 5 more ...; generated: undefined; }, {}, {}>; name: PgColumn<...>; createdAt: PgColumn<...>; updatedA...' is not assignable to parameter of type 'ZodTypeAny'.
Type 'ZodObject<{ id: ZodType<Buffer, unknown>; name: ZodType<Buffer, unknown>; createdAt: ZodNullable<ZodDate>; updatedAt: ZodNullable<ZodDate>; }, { out: {}; in: {}; }>' is missing the following properties from type 'ZodType<any, any, any>': _type, _parse, _getType, _getOrReturnCtx, and 7 more.ts(2345)
Ling Mai Jiānguǒ
Can I see the table schema that causes the problem?
MAST
MAST5mo ago
Last time I tried to reuse drizzle-zod to share schemas between Front-end and Back-end, I found that drizzle-zod was leaking into the client bundle (I don't remember if drizzle-orm was leaking too.) So I'm not sure if this is a good idea in general. It would be nice if there was a way to code gen those schemas and then share them.
👾Rnbsov
👾RnbsovOP5mo ago
@Ling Mai Jiānguǒ @⚡Z.E.U.S⚡ how do I handle my specific use case?
Andrii Sherman
Andrii Sherman5mo ago
you should import from "zod/v4" starting from drizzle-zod@0.8.1 drizzle-zod is only compatible with v4
👾Rnbsov
👾RnbsovOP5mo ago
thanks! this fixed the issue 😃👍
je823
je8235mo ago
were there any release notes about the v4 compatibility?
👾Rnbsov
👾RnbsovOP5mo ago
wish it would be covered in the docs, so I created a PR that adds this information https://github.com/drizzle-team/drizzle-orm-docs/pull/556
👾Rnbsov
👾RnbsovOP5mo ago
I've tried to move schema validators definitions from drizzle-schema package back to api-contracts, so I've installed specific version of drizzle-zod@0.8.0 there (because @ts-rest library is not yet compatible with zod v4)
👾Rnbsov
👾RnbsovOP5mo ago
and in api-contracts/src/schema-validators.ts/ I try to import schemas definitions from drizzle-schema package but I get a type error:
No overload matches this call.
The last overload gave the following error.
Argument of type 'PgTableWithColumns<{ name: "events"; schema: undefined; columns: { id: PgColumn<{ name: "id"; tableName: "events"; dataType: "number"; columnType: "PgInteger"; data: number; driverParam: string | number; notNull: true; ... 7 more ...; generated: undefined; }, {}, {}>; ... 10 more ...; updatedAt: PgColumn<...>; }; di...' is not assignable to parameter of type 'PgEnum<any>'.
Type 'PgTable<{ name: "events"; schema: undefined; columns: { id: PgColumn<{ name: "id"; tableName: "events"; dataType: "number"; columnType: "PgInteger"; data: number; driverParam: string | number; notNull: true; ... 7 more ...; generated: undefined; }, {}, {}>; ... 10 more ...; updatedAt: PgColumn<...>; }; dialect: "pg"...' is missing the following properties from type 'PgEnum<any>': enumName, enumValues, schemats(2769)
schema.types.d.cts(10, 5): The last overload is declared here.
No overload matches this call.
The last overload gave the following error.
Argument of type 'PgTableWithColumns<{ name: "events"; schema: undefined; columns: { id: PgColumn<{ name: "id"; tableName: "events"; dataType: "number"; columnType: "PgInteger"; data: number; driverParam: string | number; notNull: true; ... 7 more ...; generated: undefined; }, {}, {}>; ... 10 more ...; updatedAt: PgColumn<...>; }; di...' is not assignable to parameter of type 'PgEnum<any>'.
Type 'PgTable<{ name: "events"; schema: undefined; columns: { id: PgColumn<{ name: "id"; tableName: "events"; dataType: "number"; columnType: "PgInteger"; data: number; driverParam: string | number; notNull: true; ... 7 more ...; generated: undefined; }, {}, {}>; ... 10 more ...; updatedAt: PgColumn<...>; }; dialect: "pg"...' is missing the following properties from type 'PgEnum<any>': enumName, enumValues, schemats(2769)
schema.types.d.cts(10, 5): The last overload is declared here.
No description
👾Rnbsov
👾RnbsovOP5mo ago
I don't understand why creating validation schemas in drizzle-schema package works without any type problems, but if I try to import same table definitions and create validation schemas in api-contracts package causes issues @Ling Mai Jiānguǒ could you please help me on this one @Andrii Sherman What might be the problem? @Andrew Sherman @⚡Z.E.U.S⚡ @S. Reka What's the issue, should I create an github issue for this?

Did you find this page helpful?