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

Feat/1768 discriminated union object functions <<please review>> #1845

Conversation

teunmooij
Copy link

Implements #1768

This PR adds the following functions to the ZodDiscriminatedUnion with same functionality as the ones on ZodObject:

  • strict
  • strip
  • passthrough
  • catchall
  • pick
  • omit
  • deepPartial
  • partial
  • required
    The discriminator is not affected by any of these functions.

I've also added an expectShape test util to validate the shape of a schema.

@netlify
Copy link

netlify bot commented Jan 10, 2023

Deploy Preview for guileless-rolypoly-866f8a ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 63eb288
🔍 Latest deploy log https://app.netlify.com/sites/guileless-rolypoly-866f8a/deploys/63da8d49b779450008630651
😎 Deploy Preview https://deploy-preview-1845--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 settings.

@teunmooij teunmooij force-pushed the feat/1768-discriminated-union-object-functions branch from 9ffa384 to b8d2ed9 Compare January 14, 2023 10:40
@teunmooij
Copy link
Author

@JacobWeisenburger or @colinhacks , can I please get a review?

@JacobWeisenburger
Copy link
Contributor

I don't feel like I have enough experience to approve this big of a change. Sorry

@teunmooij teunmooij changed the title Feat/1768 discriminated union object functions Feat/1768 discriminated union object functions <<please review>> Feb 1, 2023
@teunmooij teunmooij force-pushed the feat/1768-discriminated-union-object-functions branch from b8d2ed9 to 63eb288 Compare February 1, 2023 16:03
@SpencerKaiser
Copy link

Anything holding this PR up? We've been waiting on it for a while 👀

@teunmooij
Copy link
Author

Good question. It was already taking long, but now there's also this discussion: #2106
So unfortunately I don't expect it will get merged soon. There's also some other PRs on discriminated uion older than this one, so after rebasing to fixing merge issues 3 or 4 times already I decided to wait until the other PRs are getting merged before I fix them again.

That being said... I also needed it, so I decided to just publish it myself as zod.discriminatedunion. That package also includes the work done by @maxArturo in GH-1075, which adds the option to use nested discriminated union.

@stale
Copy link

stale bot commented Jun 21, 2023

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 Jun 21, 2023
@teunmooij
Copy link
Author

Still waiting for review.

@stale stale bot removed the stale No activity in last 60 days label Jun 21, 2023
@stale
Copy link

stale bot commented Sep 19, 2023

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 Sep 19, 2023
@SpencerKaiser
Copy link

Not stale

@stale stale bot removed the stale No activity in last 60 days label Sep 19, 2023
@colinhacks
Copy link
Owner

colinhacks commented Mar 22, 2024

This is an impressive PR @teunmooij, but I'm against merging at this time. Apologies, and thanks for the great work here.

I wish I had a long and complex answer to explain why but ultimately it's simple. This is a ton of code and complexity for a feature that most people will never use. On top of that, ZodDiscriminatedUnion is likely to go away in Zod 4, specifically because it invites such complexity as this: #2106 So improving DX here isn't a priority.

@colinhacks colinhacks closed this Mar 22, 2024
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.

4 participants