Open
Description
Hi,
I have a schema like so:
const bananaSchema = z.object({
type: z.literal('fruit'),
subType: z.literal('banana'),
value: z.string(),
});
const orangeSchema = z.object({
type: z.literal('fruit'),
subType: z.literal('orange'),
value: z.string(),
});
const discriminatedFruitSchema = z.discriminatedUnion('subType', [bananaSchema, orangeSchema]);
const vegetableSchema = z.object({
type: z.literal('vegetable'),
value: z.string(),
});
export const discriminatedFoodSchema = z.discriminatedUnion('type', [
vegetableSchema,
...discriminatedFruitSchema.options,
]);
All is good at first, but when I parse using the schema I get the following error:
/.../zod/lib/types.js:2386
throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
^
Error: Discriminator property type has duplicate value fruit
Metadata
Metadata
Assignees
Labels
No labels