Allow coercing types other than Date
Is your feature request related to a problem? Please describe.
A way to coerce types such as Int from a Prisma schema. I am very new to both Prisma and Zod (first time using either) and seams the way to use a html input (which works with string) to represent a number type and db value type is to coerce it.
Describe the solution you'd like Would expect to use the following in a Prisma schema.
/// @zod.coerce.number.min(1, { message: 'Number must be greater than zero'})
someNum Int
Describe alternatives you've considered
Very tedious to write onChange handlers to coerce things manually.
Additional context
Error message
[@zod generator error]: 'coerce' is not a valid validator type.
Any update on this? I also need that functionality
@RuntimeRascal, @roman-chivo thanks for the request and sorry for the late response. :wink:
In your case you can use custom validators like
/// z.custom.use(z.coerce.number.min(1, { message: 'Number must be greater than zero'}))
someNum Int
this sould result in
someNum: z.coerce.number.min(1, { message: 'Number must be greater than zero'})
hope this helps.
I can use custom validators to "solve" this problem, but with thousands of fields that all need to be coerced, this is an extremely tedious task. A setting that allowed "maximum" coercion that coerces all "non-string" fields or something like that would be incredibly useful.
Does custom validator work only with model ?