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

Zod discriminated union discriminator value accepts zod enum #1213

Closed
wants to merge 7 commits into from

Conversation

tianhuil
Copy link

Zod discriminated union discriminator value accepts zod enum:

const item = z
  .discriminatedUnion("type", [
    z.object({ type: z.literal("a"), a: z.string() }),
    z.object({ type: z.enum(["b", "c"]), b: z.string() }),
  ])
  .parse({ type: "b", b: "abc" });

Updates test, README.md documentation, and some minor changes from lint / prettier.

Requested in #1075 and #1015.

@netlify
Copy link

netlify bot commented Jun 19, 2022

Deploy Preview for guileless-rolypoly-866f8a ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 93c0c23
🔍 Latest deploy log https://app.netlify.com/sites/guileless-rolypoly-866f8a/deploys/62e838e806f743000840bbd0
😎 Deploy Preview https://deploy-preview-1213--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.

@tianhuil
Copy link
Author

@colinhacks -- any thoughts?

@stale
Copy link

stale bot commented Sep 30, 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 Sep 30, 2022
Comment on lines +2283 to +2285
} else {
throw new Error("Invalid types provided to ZodDiscriminatedUnion");
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this runtime check and error here?

@@ -1603,7 +1603,9 @@ export type SomeZodObject = ZodObject<
any
>;

function deepPartialify(schema: ZodTypeAny): any {
export function deepPartialify<T extends ZodTypeAny>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be a better to split off this update to deepPartialify since it's not necessary for the rest of the work here.

@stale stale bot removed the stale No activity in last 60 days label Oct 5, 2022
@maxArturo
Copy link
Contributor

Hello @tianhuil @scotttrinh ! I'm wondering if this is still being worked on? It seems that the PR's feature already works. Just asking because I ran into this while implementing #1589.

@tianhuil
Copy link
Author

@scotttrinh / @maxArturo: I'm happy to resubmit with just the changes concerning deepPartialify() to add union and discriminated union, if that is still of interest. Sorry, I stopped paying attention once the issue became stale but happy to re-engage.

@stale
Copy link

stale bot commented Jul 23, 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 Jul 23, 2023
@stale stale bot closed this Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale No activity in last 60 days
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants