library for converting form data to an object based on zod model
hello. is there a library that can convert form data submitted, which will be all strings into an object based on a zod model that I create with zod-prisma, that does not have preprocess or transform applied to it?
4 Replies
GitHub
GitHub - colinhacks/zod: TypeScript-first schema validation with st...
TypeScript-first schema validation with static type inference - GitHub - colinhacks/zod: TypeScript-first schema validation with static type inference
thank you.
is there a way to get zod to replace all instances of the string "null" with actual null for fields that are supposed to be non-string? for example, I have this in my zod schema
isCustomer: z.boolean().transform(val => val === "null" ? null : val).nullish(),
since all my data is coming from a form and all actual nulls that are logged as such on devtools makes it over to the server as "null" and I'm trying to clean it up before or during validation.
for lines like the above, I get this error: This condition will always return 'false' since the types 'boolean' and 'string' have no overlap.ts(2367)
Transform or preprocess can do that
Just read the zod docs top to bottom once
It’s worth it
thank you. yeah. I think I was looking for preprocessing. it's kind of tricky since I'm trying to get it to work with https://github.com/CarterGrimmeisen/zod-prisma which is a bit more rigid on how it generates the zod models
GitHub
GitHub - CarterGrimmeisen/zod-prisma: A custom prisma generator tha...
A custom prisma generator that creates Zod schemas from your Prisma model. - GitHub - CarterGrimmeisen/zod-prisma: A custom prisma generator that creates Zod schemas from your Prisma model.