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

Adding a .required helper on object (v3) #357

Closed
fabien0102 opened this issue Mar 24, 2021 · 2 comments
Closed

Adding a .required helper on object (v3) #357

fabien0102 opened this issue Mar 24, 2021 · 2 comments

Comments

@fabien0102
Copy link

Hello,

Since we have an amazing z.object().partial() helper (https://github.com/colinhacks/zod/tree/v3#partial) to mimic the typescript Partial<> util, this could be nice have the symetrical Required<> util.

Ideally, I would like something like this:

.required

Inspired by the built-in TypeScript utility type Required, the .required method makes all properties required.

Starting from this object:

const user = z.object({
  username: z.string().optional(),
});
// { username?: string | undefined }

We can create a required version:

const requiredUser = user.required();
// { username: string }
@colinhacks
Copy link
Owner

colinhacks commented Mar 25, 2021

Great idea, this has been on my to-do list for a long time.

Just shipped this feature in alpha.32, upgrade to the latest version to access this: npm install zod@next

@fabien0102
Copy link
Author

Just amazing! Thanks for your reactivity, this was my last missing for a typescript to zod generator #teasing 😁

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

2 participants