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
When omit is used to modify a schema, that schema causes an error when passed to zod resolver.
To Reproduce
I have a base schema for an Account.
exportconstAccountSchema=z.object({uid: z.string().uuid(),name: z.string({invalid_type_error: 'Please enter an account name.',}).pipe(nonempty),type: z.enum(['manual','auto'],{invalid_type_error: 'Please select a valid account type.',}),})
For create form I extend this schema, omitting the uid
I've worked around this by spitting my schema up into two parts.
exportconstBaseAccountSchema=z.object({uid: z.string().uuid(),})exportconstCreateAccountSchema=x.object({name: z.string({invalid_type_error: 'Please enter an account name.',}).pipe(nonempty),type: z.enum(['manual','auto'],{invalid_type_error: 'Please select a valid account type.',}),})exportconstAccountSchema=BaseAccountSchema.merge(CreateAccountSchema)
This way I can use the CreateAccountSchema in the form and AccountSchema wherever I need to validate the full object
I encountered this issue too, and my solution was quite similar to yours.
Here’s an example with the same context:
exportconstAccountSchema=z.object({uid: z.string().uuid(),name: z.string({invalid_type_error: 'Please enter an account name.',}).pipe(nonempty),type: z.enum(['manual','auto'],{invalid_type_error: 'Please select a valid account type.',}),})
Describe the bug
When
omit
is used to modify a schema, that schema causes an error when passed to zod resolver.To Reproduce
I have a base schema for an Account.
For create form I extend this schema, omitting the
uid
When the latter schema is passed to the resolver
I see this error when I try to submit / trigger form etc
If instead I pass
AccountSchema
like this, there is no errorI'm not able to create code sandbox using this template - it opens in a beta version and there are no files / edit controls..?
Expected behavior
Expect the Schema with omit applied to work the same as the original schema - e.g. not throw an error
The text was updated successfully, but these errors were encountered: