check if a key is required on a zod object
is there a way to tell if a key on a zod object is required
edit: is there a way to tell if a key on a zod object is required in typescript programmatically
4 Replies
by required i mean cant be
undefined
what do you mean by "way to tell"?
you can read the schema
like in a text input component i have a required field
i have a form with a zod form schema, and I want to tell if a field is required based off of the key name
so I don't have to manually pass required
oh right
id suggest using react-hook-form or similar
email: z.string().min(1, "The email is required.") - then its required
if you want to build it yourself, zod has a discord (link in their docs), im sure someone on there will know