web: Use Zod z.discriminatedUnion more.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2024-03-02 12:14:53 -08:00
committed by Anders Kaseorg
parent a03a26151c
commit aaa6f16538
2 changed files with 6 additions and 3 deletions

View File

@@ -36,7 +36,7 @@ const draft_schema = z.intersection(
content: z.string(), content: z.string(),
updatedAt: z.number(), updatedAt: z.number(),
}), }),
z.union([ z.discriminatedUnion("type", [
z.object({ z.object({
type: z.literal("stream"), type: z.literal("stream"),
topic: z.string(), topic: z.string(),
@@ -61,7 +61,7 @@ const possibly_buggy_draft_schema = z.intersection(
content: z.string(), content: z.string(),
updatedAt: z.number(), updatedAt: z.number(),
}), }),
z.union([ z.discriminatedUnion("type", [
z.object({ z.object({
type: z.literal("stream"), type: z.literal("stream"),
topic: z.string().optional(), topic: z.string().optional(),

View File

@@ -43,7 +43,10 @@ const one_time_notice_schema = z.object({
type: z.literal("one_time_notice"), type: z.literal("one_time_notice"),
}); });
const onboarding_step_schema = z.union([one_time_notice_schema, hotspot_schema]); const onboarding_step_schema = z.discriminatedUnion("type", [
one_time_notice_schema,
hotspot_schema,
]);
export type OnboardingStep = z.output<typeof onboarding_step_schema>; export type OnboardingStep = z.output<typeof onboarding_step_schema>;