Skip to main content
Deno 2 is finally here 🎉️
Learn more
Go to Latest
class zod.z.ZodDiscriminatedUnion
import { zod } from "https://deno.land/x/cav@0.0.24/test/test_deps.ts";
const { ZodDiscriminatedUnion } = zod.z;

Type Parameters

Discriminator extends string
DiscriminatorValue extends Primitive

Properties

readonly
discriminator
readonly
options
readonly
validDiscriminatorValues

Methods

_parse(input: ParseInput): ParseReturnType<this["_output"]>

Static Methods

create<Discriminator extends string, DiscriminatorValue extends Primitive, Types extends [ZodDiscriminatedUnionOption<Discriminator, DiscriminatorValue>, ZodDiscriminatedUnionOption<Discriminator, DiscriminatorValue>, ...ZodDiscriminatedUnionOption<Discriminator, DiscriminatorValue>[]]>(
discriminator: Discriminator,
types: Types,
params?: RawCreateParams,
): ZodDiscriminatedUnion<Discriminator, DiscriminatorValue, Types[number]>

The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor. However, it only allows a union of objects, all of which need to share a discriminator property. This property must have a different value for each object in the union.