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
ott
ott2y ago
by required i mean cant be undefined
cje
cje2y ago
what do you mean by "way to tell"? you can read the schema
ott
ott2y ago
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
cje
cje2y ago
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
Want results from more Discord servers?
Add your server