Replies: 1 comment 11 replies
-
This would likely take the form of a higher-level z.discriminatedUnion([
z.object({ kind: z.literal('a'), data1: z.string() }),
z.object({ kind: z.literal('b'), data2: z.string() }),
z.object({ kind: z.literal('c'), data3: z.string() }),
], 'kind') With some static validation to make sure |
Beta Was this translation helpful? Give feedback.
11 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Would it make sense to set some fields as "type marker", meaning if those fields fail validation, no other fields need to be checked for that schema, moving on to the first parent union member?
We could then mark some fields, and avoid many errors that are due to checking the wrong types (and, when that happens, we end up looking for those fields anyway to see which type was the intended one).
Something like this:
Beta Was this translation helpful? Give feedback.
All reactions