// Loaded from https://raw.githubusercontent.com/colinhacks/zod/654680afc2ede388e71e09104eac5a0088fe3207/deno/lib/types/union.ts import { ZodTypes } from "../ZodTypes.ts"; import { ZodType, ZodTypeDef, ZodTypeAny } from "./base.ts"; // import { ZodUndefined } from './undefined'; // import { ZodNull } from './null'; export interface ZodUnionDef< T extends [ZodTypeAny, ZodTypeAny, ...ZodTypeAny[]] = [ ZodTypeAny, ZodTypeAny, ...ZodTypeAny[] ] > extends ZodTypeDef { t: ZodTypes.union; options: T; } export class ZodUnion< T extends [ZodTypeAny, ZodTypeAny, ...ZodTypeAny[]] > extends ZodType, T[number]["_input"]> { // opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]); // null nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]); toJSON = (): object => ({ t: this._def.t, options: this._def.options.map((x) => x.toJSON()), }); get options() { return this._def.options; } // distribute = ZodTypeAny>(f: F): ZodUnion<{ [k in keyof T]: ReturnType }> => { // return ZodUnion.create(this._def.options.map(f) as any); // }; static create = ( types: T ): ZodUnion => { return new ZodUnion({ t: ZodTypes.union, options: types, }); }; }