chrishoermann / zod-prisma-types

Generator creates zod types for your prisma models with advanced validation
Other
579 stars 43 forks source link

TS2339: Property 'pick' does not exist on type 'ZodType '. #158

Closed cesarve77 closed 11 months ago

cesarve77 commented 1 year ago

zod-prisma-types

generate schemas like:

export const UserSchema: z.ZodType<Prisma.UserCreateInput> = z.object({
  id: z.string().uuid().optional(),
  name: z.string.optional(),
})

then if I try to

const NameSchema = UserSchema.pick({name: true});

Typescript throw this error:

TS2339: Property 'pick' does not exist on type 'ZodType '.

It can solved using 4.9 TS feature satifsatisfiesaces

export const UserSchema = z.object({
  id: z.string().uuid().optional(),
  name: z.string.optional()
}).strict() satisfies z.ZodType<Prisma.OfferCreateInput> 

here a demo

https://stackblitz.com/edit/typescript-prb2b6?file=index.ts

chrishoermann commented 11 months ago

@cesarve77 Thanks for the question but this is not possible since zod requires a type annotation for recursive types to work as mentioned #140.