You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ZodCatch I initially thought I could handle as if nothing happened, however, it seems to accept undefined which makes it technically optional. I believe consumers should be able to mark this as a required schema since we have .default() to be able to handle undefined values.
I think it would be helpful for consumers to be able to catch the error, and to rethrow/or return a ZodError if they think it should be still flagged as invalid.
eg.
constschema=z.string().min(1).catch((ctx)=>{if(ctx.input===undefined){throwctx.error;}return'foo'})schema.safeParse(undefined);// Does not throwschema.isOptional()// false
It would be akin to z.string().optional() with .refine() but your input boundary would be introspectable as non optional
The text was updated successfully, but these errors were encountered:
I was working on my library: https://github.com/samchungy/zod-openapi and was trying to simplify how I determine if a schema should be "required".
ZodCatch
I initially thought I could handle as if nothing happened, however, it seems to acceptundefined
which makes it technically optional. I believe consumers should be able to mark this as a required schema since we have.default()
to be able to handleundefined
values.I think it would be helpful for consumers to be able to catch the error, and to rethrow/or return a ZodError if they think it should be still flagged as invalid.
eg.
It would be akin to
z.string().optional()
with.refine()
but your input boundary would be introspectable as non optionalThe text was updated successfully, but these errors were encountered: