// Loaded from https://raw.githubusercontent.com/colinhacks/zod/654680afc2ede388e71e09104eac5a0088fe3207/deno/lib/types/nullable.ts import { ZodTypes } from "../ZodTypes.ts"; import { ZodType, ZodTypeDef, ZodTypeAny } from "./base.ts"; export interface ZodNullableDef extends ZodTypeDef { t: ZodTypes.nullable; innerType: T; } // This type allows for nullable flattening export type ZodNullableType< T extends ZodTypeAny > = T extends ZodNullable ? T : ZodNullable; export class ZodNullable< T extends ZodTypeAny // Output extends T['_output'] | null = T['_output'] | null, // Input extends T['_input'] | null = T['_input'] | null > extends ZodType, T["_input"] | null> { // An nullable nullable is the original nullable // nullable: () => ZodNullableType = () => this as ZodNullableType; toJSON = () => ({ t: this._def.t, innerType: this._def.innerType.toJSON(), }); static create = (type: T): ZodNullableType => { if (type instanceof ZodNullable) return type as ZodNullableType; return new ZodNullable({ t: ZodTypes.nullable, innerType: type, }) as ZodNullableType; }; }