Replies: 1 comment
-
UpdateI'm now solving this with DropzoneError.parse({
type: 'missing_items_list',
} satisfies NewDropzoneError),
// with NewDropzoneError being
export type NewDropzoneError = z.input<typeof DropzoneError>; It's a little boilerplatey but works ^^ Still, having a .new() function for this would be very nice :) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I would like to have a .new() function on a Schema to be able to create an object according to the Schema by hand.
Example
I have the following zod Schemas:
I'd like to create these Objects like this:
Why not use .parse()?
When using .parse() with a new object, I don't get autocomplete for the 'type' param => have to double check the plain string i pass there, or I have to wait for the runtime error to happen and catch it that way.
Also, when using z.infer, message is not optional anymore (which is correct).
But then I would have to export z.input additionally to z.infer which clutters my files.
Why add a .new() function?
Beta Was this translation helpful? Give feedback.
All reactions