Closed nordowl closed 10 months ago
Closing this as the error was my fault. The path to the Prisma client changed from node_modules/@prisma/client
to node_modules/.prisma/client
and I didn't notice. Because of that, Prisma.DecimalJsLike
didn't resolve.
On one of my Prisma models I'm using a decimal field
myfield Decimal @db.Decimal(20, 5)
. I redacted most fields because I'd rather not hint at what I'm building.zod-prisma-types generates this Zod type from that field:
z.union([z.number(),z.string(),DecimalJSLikeSchema,]).refine((v) => isValidDecimalInput(v), { message: "Field 'myfield' must be a Decimal. Location: [redacted]", })
If I hover over the whole Zod schema object generated for that model, Intellisense shows me this type for that field:
z.ZodEffects<z.ZodUnion<[z.ZodNumber, z.ZodString, z.ZodType<Prisma.DecimalJsLike, z.ZodTypeDef, Prisma.DecimalJsLike>]>, any, any>
However, when the type is exported like this
export type MyType = z.infer<typeof MyTypeSchema>
, the property onMyType
suddenly becomes optional and is of typeany
. This means you lose type safety for that property.Occurred using
"zod-prisma-types": "^2.7.9"
,"zod": "^3.22.0",
and"prisma": "^5.1.1",
. Also tested with"zod-prisma-types": "^2.7.7"
,"zod": "^3.21.1",
and"prisma": "^5.1.1",
- same problem.