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

Restrict .pick()/.omit() mask type to only known properties #3255

Conversation

petrovmiroslav
Copy link
Contributor

Current

Both the methods .pick and .omit accept properties that don't exist in the schema.

const schema = z.object({
  existedProperty: z.string(),
});

const pick = schema.pick({
  existedProperty: true,
  NOT_existed_property: true, // there is no TypeScript error
});

Fixed

Both the methods .pick and .omit now only accept known properties.

const schema = z.object({
  existedProperty: z.string(),
});

const pick = schema.pick({
  existedProperty: true,
  NOT_existed_property: true, // there is a TypeScript error
});

resolves #895

Copy link

netlify bot commented Feb 19, 2024

Deploy Preview for guileless-rolypoly-866f8a ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 8d364f0
🔍 Latest deploy log https://app.netlify.com/sites/guileless-rolypoly-866f8a/deploys/65d31b03a96a09000805d377
😎 Deploy Preview https://deploy-preview-3255--guileless-rolypoly-866f8a.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@colinhacks colinhacks merged commit 1d2bc9b into colinhacks:master Apr 8, 2024
4 checks passed
@colinhacks
Copy link
Owner

Thank you! Fascinating that this works...

@colinhacks
Copy link
Owner

This has landed in Zod 3.23.

https://github.com/colinhacks/zod/releases/tag/v3.23.0

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

Successfully merging this pull request may close these issues.

.pick() mask allowing non-present props when present props are defined
2 participants