zod icon indicating copy to clipboard operation
zod copied to clipboard

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

Open petrovmiroslav opened this issue 1 year ago • 1 comments

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 https://github.com/colinhacks/zod/issues/895

petrovmiroslav avatar Feb 19 '24 09:02 petrovmiroslav

Deploy Preview for guileless-rolypoly-866f8a ready!

Built without sensitive environment variables

Name Link
Latest commit 8d364f029614dec32c1852d0bdabbebee8d4bb58
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.

netlify[bot] avatar Feb 19 '24 09:02 netlify[bot]

Thank you! Fascinating that this works...

colinhacks avatar Apr 08 '24 22:04 colinhacks

This has landed in Zod 3.23.

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

colinhacks avatar Apr 21 '24 22:04 colinhacks