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

Discriminated union, cover case where discriminator is missing #3868

Open
lukasoppermann opened this issue Nov 22, 2024 · 0 comments
Open

Discriminated union, cover case where discriminator is missing #3868

lukasoppermann opened this issue Nov 22, 2024 · 0 comments

Comments

@lukasoppermann
Copy link

Hey, basically I am validating some json. I have the following setup:

return z.union([
      z.discriminatedUnion('$type', [
        colorToken,
        cubicBezierToken,
        dimensionToken,
        shadowToken,
        borderToken,
        fontFamilyToken,
        fontWeightToken,
        typographyToken,
        viewportRangeToken,
        numberToken,
        durationToken,
        stringToken,
      ]),
      designToken,
    ])

This works really, well, however I would love to add a referenceToken which does NOT have a $type property. This is the only one without the $type property so this is how it could be differentiated. But I don't know how I can implement this in zod. Any ideas? Is this even possible?

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

1 participant