interface-forge - v2.5.0
    Preparing search index...

    Interface ZodUnion<T>

    interface ZodUnion<T extends readonly SomeType[] = readonly $ZodType[]> {
        _def: $ZodUnionDef<T>;
        _input: $InferUnionInput<T[number]>;
        _output: $InferUnionOutput<T[number]>;
        _zod: $ZodUnionInternals;
        "~standard": $ZodStandardSchema<ZodUnion<T>>;
        def: $ZodUnionDef<T>;
        description?: string;
        options: T;
        spa: (
            data: unknown,
            params?: ParseContext<$ZodIssue>,
        ) => Promise<ZodSafeParseResult<$InferUnionOutput<T[number]>>>;
        type: "union";
        and<T extends SomeType>(incoming: T): ZodIntersection<ZodUnion<T>, T>;
        array(): ZodArray<ZodUnion<T>>;
        brand<T extends PropertyKey = PropertyKey>(
            value?: T,
        ): PropertyKey extends T ? ZodUnion<T> : $ZodBranded<ZodUnion<T>, T>;
        catch(def: $InferUnionOutput<T[number]>): ZodCatch<ZodUnion<T>>;
        catch(
            def: (ctx: $ZodCatchCtx) => $InferUnionOutput<T[number]>,
        ): ZodCatch<ZodUnion<T>>;
        check(
            ...checks: (
                | CheckFn<$InferUnionOutput<T[number]>>
                | $ZodCheck<$InferUnionOutput<T[number]>>
            )[],
        ): this;
        clone(def?: $ZodUnionDef<T>, params?: { parent: boolean }): this;
        default(def: $InferUnionOutput<T[number]>): ZodDefault<ZodUnion<T>>;
        default(
            def: () => NoUndefined<$InferUnionOutput<T[number]>>,
        ): ZodDefault<ZodUnion<T>>;
        describe(description: string): this;
        isNullable(): boolean;
        isOptional(): boolean;
        meta(): | undefined
        | {
            deprecated?: boolean;
            description?: string;
            example?: unknown;
            examples?: | unknown[]
            | { [key: string]: { value: unknown; [key: string]: unknown } };
            id?: string;
            title?: string;
            [key: string]: unknown;
        };
        meta(
            data: {
                deprecated?: boolean;
                description?: string;
                example?: unknown;
                examples?:
                    | unknown[]
                    | { [key: string]: { value: unknown; [key: string]: unknown } };
                id?: string;
                title?: string;
                [key: string]: unknown;
            },
        ): this;
        nonoptional(
            params?:
                | string
                | {
                    error?: string
                    | $ZodErrorMap<$ZodIssueInvalidType<unknown>>;
                    message?: string;
                },
        ): ZodNonOptional<ZodUnion<T>>;
        nullable(): ZodNullable<ZodUnion<T>>;
        nullish(): ZodOptional<ZodNullable<ZodUnion<T>>>;
        optional(): ZodOptional<ZodUnion<T>>;
        or<T extends SomeType>(option: T): ZodUnion<[ZodUnion<T>, T]>;
        overwrite(
            fn: (x: $InferUnionOutput<T[number]>) => $InferUnionOutput<T[number]>,
        ): this;
        parse(
            data: unknown,
            params?: ParseContext<$ZodIssue>,
        ): $InferUnionOutput<T[number]>;
        parseAsync(
            data: unknown,
            params?: ParseContext<$ZodIssue>,
        ): Promise<$InferUnionOutput<T[number]>>;
        pipe<
            T extends
                $ZodType<
                    any,
                    $InferUnionOutput<T[number]>,
                    $ZodTypeInternals<any, $InferUnionOutput<T[number]>>,
                >,
        >(
            target:
                | T
                | $ZodType<
                    any,
                    $InferUnionOutput<T[number]>,
                    $ZodTypeInternals<any, $InferUnionOutput<T[number]>>,
                >,
        ): ZodPipe<ZodUnion<T>, T>;
        prefault(def: () => $InferUnionInput<T[number]>): ZodPrefault<ZodUnion<T>>;
        prefault(def: $InferUnionInput<T[number]>): ZodPrefault<ZodUnion<T>>;
        readonly(): ZodReadonly<ZodUnion<T>>;
        refine(
            check: (arg: $InferUnionOutput<T[number]>) => unknown,
            params?:
                | string
                | {
                    abort?: boolean;
                    error?: string
                    | $ZodErrorMap<NonNullable<$ZodIssue>>;
                    message?: string;
                    params?: Record<string, any>;
                    path?: PropertyKey[];
                },
        ): this;
        register<
            R extends
                $ZodRegistry<
                    MetadataType,
                    $ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>,
                >,
        >(
            registry: R,
            ...meta: ZodUnion<T> extends R["_schema"]
                ? undefined extends R["_meta"]
                    ? [$replace<R["_meta"], R["_schema"] & ZodUnion<T>>?]
                    : [$replace<R["_meta"], R["_schema"] & ZodUnion<T>>]
                : ["Incompatible schema"],
        ): this;
        safeParse(
            data: unknown,
            params?: ParseContext<$ZodIssue>,
        ): ZodSafeParseResult<$InferUnionOutput<T[number]>>;
        safeParseAsync(
            data: unknown,
            params?: ParseContext<$ZodIssue>,
        ): Promise<ZodSafeParseResult<$InferUnionOutput<T[number]>>>;
        superRefine(
            refinement: (
                arg: $InferUnionOutput<T[number]>,
                ctx: RefinementCtx<$InferUnionOutput<T[number]>>,
            ) => void | Promise<void>,
        ): this;
        transform<NewOut>(
            transform: (
                arg: $InferUnionOutput<T[number]>,
                ctx: RefinementCtx<$InferUnionOutput<T[number]>>,
            ) => NewOut | Promise<NewOut>,
        ): ZodPipe<
            ZodUnion<T>,
            ZodTransform<Awaited<NewOut>, $InferUnionOutput<T[number]>>,
        >;
    }

    Type Parameters

    Hierarchy (View Summary)

    Index

    Properties

    Use .def instead.

    _input: $InferUnionInput<T[number]>

    Use z.input<typeof schema> instead.

    _output: $InferUnionOutput<T[number]>

    Use z.output<typeof schema> instead.

    description?: string
    options: T
    spa: (
        data: unknown,
        params?: ParseContext<$ZodIssue>,
    ) => Promise<ZodSafeParseResult<$InferUnionOutput<T[number]>>>
    type: "union"

    Methods

    • Parameters

      Returns this

    • Returns a new instance that has been registered in z.globalRegistry with the specified description

      Parameters

      • description: string

      Returns this

    • Returns boolean

      Try safe-parsing null (this is what isNullable does internally):

      const schema = z.string().nullable();
      const isNullable = schema.safeParse(null).success; // true
    • Returns boolean

      Try safe-parsing undefined (this is what isOptional does internally):

      const schema = z.string().optional();
      const isOptional = schema.safeParse(undefined).success; // true
    • Returns the metadata associated with this instance in z.globalRegistry

      Returns
          | undefined
          | {
              deprecated?: boolean;
              description?: string;
              example?: unknown;
              examples?: | unknown[]
              | { [key: string]: { value: unknown; [key: string]: unknown } };
              id?: string;
              title?: string;
              [key: string]: unknown;
          }

    • Returns a new instance that has been registered in z.globalRegistry with the specified metadata

      Parameters

      • data: {
            deprecated?: boolean;
            description?: string;
            example?: unknown;
            examples?:
                | unknown[]
                | { [key: string]: { value: unknown; [key: string]: unknown } };
            id?: string;
            title?: string;
            [key: string]: unknown;
        }

      Returns this

    • Parameters

      • check: (arg: $InferUnionOutput<T[number]>) => unknown
      • Optionalparams:
            | string
            | {
                abort?: boolean;
                error?: string
                | $ZodErrorMap<NonNullable<$ZodIssue>>;
                message?: string;
                params?: Record<string, any>;
                path?: PropertyKey[];
            }
        • string
        • {
              abort?: boolean;
              error?: string | $ZodErrorMap<NonNullable<$ZodIssue>>;
              message?: string;
              params?: Record<string, any>;
              path?: PropertyKey[];
          }
          • Optionalabort?: boolean

            If true, no later checks will be executed if this check fails. Default false.

          • Optionalerror?: string | $ZodErrorMap<NonNullable<$ZodIssue>>
          • Optionalmessage?: string

            This parameter is deprecated. Use error instead.

          • Optionalparams?: Record<string, any>
          • Optionalpath?: PropertyKey[]

      Returns this

    • Type Parameters

      Parameters

      • registry: R
      • ...meta: ZodUnion<T> extends R["_schema"]
            ? undefined extends R["_meta"]
                ? [$replace<R["_meta"], R["_schema"] & ZodUnion<T>>?]
                : [$replace<R["_meta"], R["_schema"] & ZodUnion<T>>]
            : ["Incompatible schema"]

      Returns this