Replies: 1 comment
-
hi @bstro, you can leverage the z.undefined() primitive inside the union. z.union(
[
z.object({ foo: z.string(), bar: z.undefined() }),
z.object({ bar: z.string(), foo: z.undefined() })
]
) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Given the following simple schema with attached
refine
logic:In this hypothetical scenario that mirrors some acceptance criteria, I need to surface an error to the user if they have supplied both
foo
andbar
. However, when I try to parse an object likeexampleUnion.parse({foo: 'hello world', bar: 'test' })
, the resulting output keeps the first member of the union and strips out the rest:Any ideas how I can detect whether the end user has passed both
foo
andbar
?Reproduction
https://stackblitz.com/edit/vitejs-vite-3vwqsq?file=package.json,src%2Fmain.ts&terminal=dev
Beta Was this translation helpful? Give feedback.
All reactions