-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Merge not supported by union types #147
Comments
That's right, you'd have to do this at the top level: const IntersectionType = z.union([
Type2.merge(Type1Sub1),
Type2.merge(Type1Sub2)
]); It's essentially the same in terms of lines-of-code and way more readable/understandable. It also eliminates a lot of internal parsing complexity associated with intersections. |
One question though, is I'm building a small openapi to zod tool. The ability to chain the calls together is really useful for spitting the code while reading the openapi json. |
Can you elaborate on this? |
Something like this:
|
Okay this seems like a valid use case. I'll leave z.intersection alone for now 😛 I removed the deprecation notice. |
Thank you 😁 |
You bet :) |
In case someon wants a more low level solution rather than intersection:
|
I saw that
z.intersection
is being deprecated in favor ofmerge
, but the later does not yet supportunion
types.edit: updated with objects, primitives don't make much sense here
The text was updated successfully, but these errors were encountered: