Closed cimchd closed 7 months ago
Describe the bug In a Prisma Schema with a Decimal field:
model Article { id String @id @unique @default(cuid()) name String @unique price Decimal? @db.Decimal(12, 2) }
The generated zod schema imports Prisma as a type but uses Prisma.Decimal for instanceof where it has to be the actual class and not the type.
// generated/zod/index.ts import { z } from 'zod'; import type { Prisma } from '../../../prisma/generated/client'; //[...] ///////////////////////////////////////// // ARTICLE SCHEMA ///////////////////////////////////////// export const ArticleSchema = z.object({ id: z.string().cuid(), name: z.string(), price: z.instanceof(Prisma.Decimal, { message: "Field 'price' must be a Decimal. Location: ['Models', 'App']"}).nullable(), }) export type Article = z.infer<typeof ArticleSchema>
Screenshots
Package versions (please complete the following information):
{ "@prisma/client": "^5.5.2", "prisma": "^5.5.2", "zod": "^3.22.4", "zod-prisma-types": "^3.1.4" }
Additional context This error occured after upgrading form version 2.8.1 to 3.1.4
@cimchd thanks for pointing this out. I missed to update the imports in singleFileMode. Should work now in latest version.
Describe the bug In a Prisma Schema with a Decimal field:
The generated zod schema imports Prisma as a type but uses Prisma.Decimal for instanceof where it has to be the actual class and not the type.
Screenshots![image](https://github.com/chrishoermann/zod-prisma-types/assets/49520229/c3bc15b9-e091-4333-b1c5-652bcf38a97e)
Package versions (please complete the following information):
Additional context This error occured after upgrading form version 2.8.1 to 3.1.4