zod
zod copied to clipboard
Allow specific properties to be `.required`
I have a mySchema with ~10 properties.
In my API, I use mySchema.partial() as all props are optional, BUT one.
I wish I could simply mySchema.partial().required({ myRequired: true }), as partial allows.
It would be a better solution than .partial({ 9 props }) or merging with the mySchema.shape.myRequired.
+1 fo this, it is very common scenario.
For example I have a orderSchema and I have an updateOrder() function that takes orderSchema.partial() (listing each key in the partial() function would be too tedious), but I want the orderSchema.shape.id property to be required, so I would like to do orderSchema.partial().required({id:true}) instead of the hack I am currently using orderSchema.partial().omit({id:true}).extend({id: orderIdSchema})
+1 -- would like this so zod can mirror the TypeScript Required utility type https://www.typescriptlang.org/docs/handbook/utility-types.html#requiredtype
+1, I also needed this feature, thanks for your workaround @ivosabev
Just implemented it in #1315.
Can you please take a look, @colinhacks?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Up
Merged in #1315