Open BriungRi opened 4 months ago
Maybe you can try coerce
(https://zod.dev/?id=coercion-for-primitives)
z.object({
name: z.string(),
age: z.coerce.number(),
});
Because I am very desired to use z.number(), I created a plugin because of this, feel free to take a look: fastify-zod-query-coercion
Currently,
querystring
can accept something likewhich will always fail the validation because all parameters from
querystring
arestring
type.A few ideas:
querystring
only, if anumber
is expected, parse the string into a number and then do zod validationquerystring
typequerystring
type by throwing an error for invalid type