x/zod/mod.ts

TypeScript-first schema validation with static type inference
Very Popular
Go to Latest
class ZodDiscriminatedUnion
extends ZodType<Option["_output"], ZodDiscriminatedUnionDef<Discriminator, DiscriminatorValue, Option>, Option["_input"]>
import { ZodDiscriminatedUnion } from "https://deno.land/x/zod@v3.17.3/mod.ts?s=ZodDiscriminatedUnion";

Type Parameters

Discriminator extends string[src]
DiscriminatorValue extends Primitive[src]
Option extends ZodDiscriminatedUnionOption<Discriminator, DiscriminatorValue>[src]

Properties

readonly
discriminator
[src]
readonly
options
[src]
readonly
validDiscriminatorValues
[src]

Methods

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

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]>
[src]

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.