Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specific properties to be .required #1176

Closed
SrBrahma opened this issue May 30, 2022 · 7 comments
Closed

Allow specific properties to be .required #1176

SrBrahma opened this issue May 30, 2022 · 7 comments

Comments

@SrBrahma
Copy link
Contributor

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.

@SrBrahma SrBrahma changed the title [.required()] Allow specific properties to be required. [.required()] Allow specific properties to be required May 30, 2022
@ivosabev
Copy link

ivosabev commented Jun 28, 2022

+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})

@Antman261
Copy link

+1 -- would like this so zod can mirror the TypeScript Required utility type https://www.typescriptlang.org/docs/handbook/utility-types.html#requiredtype

@yannbcf
Copy link

yannbcf commented Aug 4, 2022

+1, I also needed this feature, thanks for your workaround @ivosabev

@SrBrahma
Copy link
Contributor Author

SrBrahma commented Aug 5, 2022

Just implemented it in #1315.

Can you please take a look, @colinhacks?

@SrBrahma SrBrahma changed the title [.required()] Allow specific properties to be required Allow specific properties to be .required Aug 5, 2022
@stale
Copy link

stale bot commented Oct 4, 2022

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.

@stale stale bot added the stale No activity in last 60 days label Oct 4, 2022
@SrBrahma
Copy link
Contributor Author

SrBrahma commented Oct 4, 2022

Up

@stale stale bot removed the stale No activity in last 60 days label Oct 4, 2022
@SrBrahma
Copy link
Contributor Author

SrBrahma commented Oct 5, 2022

Merged in #1315

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants