Open atanaskanchev opened 1 year ago
@atanaskanchev thank's for the report. I'm aware of this issue and currently working on a fix for that. This has to do with an updated Prisma XOR
type that does not accept a simple union anymore.
@atanaskanchev this seems to be a bit of a complex issue. I've started a discussion on the zod page on how this could be resolved.
I rolled back Zod to 3.21.1 from 3.21.2 and that's getting me past this issue.
Opened an issue in the zod repo: https://github.com/colinhacks/zod/issues/2184
I tried rolling back but ran into this error:
Property 'coerce' does not exist on type 'typeof import(\"/path/to/project/node_modules/zod/lib/external\")'.
export const UserSchema = z.object({
id: z.string().cuid(),
name: z.string().nullable(),
email: z.string(),
createdAt: z.coerce.date(),
updatedAt: z.coerce.date(),
})
I rolled back Zod to 3.21.1 from 3.21.2 and that's getting me past this issue.
I was able to get around this as well by rolling back to 3.21.1 from 3.21.4
Since there is no movement on the zod issue I thought of a rude override to enable the use of zod version greater than 3.21.1
:
The simple solution for now would be to just add a type assertion like:
export const UserCreateInputSchema: z.ZodType
since the schemas work, as confirmd by using zod 3.21,1
there should be little risk that the behavior breaks when using type assertions. But as mentioned above it feels like a dirty hack that hurts my typesafe heart a little bit and that should actually not be needed.
Any thougths on this? should probably be swichable via generator option and off by default.
Rolling back zod to 3.21.1 leads to my project not working any more. The reason is that this project uses uuid v7 and it seems that zod does not recognize uuid v7 as valid until later versions (3.22.4 works). For more info see https://github.com/electric-sql/electric/issues/1153#issuecomment-2055583872
zod 3.23 has been released, and may include a fix for the XOR issue: https://github.com/colinhacks/zod/issues/2184#ref-pullrequest-2254755159
zod-prisma-types generates a schema for a field missing in the prisma generated types
The Prisma schema
the generated zod type having an error
the generated prisma type
the ts error