Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/zod/index.ts>z.ZodDiscriminatedUnion

TypeScript-first schema validation with static type inference
Extremely Popular
Go to Latest
class z.ZodDiscriminatedUnion
import { z } from "https://deno.land/x/zod@v3.23.2/index.ts";
const { ZodDiscriminatedUnion } = z;

Type Parameters

Discriminator extends string

Properties

readonly
discriminator
readonly
options
readonly
optionsMap

Methods

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

Static Methods

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

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.