Nested z.discriminatedUnion
#2377
Unanswered
antoniogiroz
asked this question in
Q&A
Replies: 1 comment 3 replies
-
This works: const PipelineSchema = z.discriminatedUnion('executionMode', [
BasePipelineSchema.extend({
executionMode: z.literal('Manual'),
}),
BasePipelineSchema.extend({
executionMode: z.literal('Periodical'),
executionFrequencyMode: z.literal('Simple'),
frequencyValue: z.number(),
frequencyUnit: PipelineFrequencyUnit,
}),
BasePipelineSchema.extend({
executionMode: z.literal('Periodical'),
executionFrequencyMode: z.literal('Advanced'),
frequencyValue: z.string(),
}),
]); But I'd like to know if there is a better way. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello!
I'm trying to pass from this type:
To that:
Where
executionMode
andexecutionFrequencyMode
should be discriminated unions.I'm trying something like the following, but I get typescript errors:
Is it possible to add more nested discriminated unions?
Thanks a lot!
Beta Was this translation helpful? Give feedback.
All reactions