import type * as core from "../core/index.js"; import { visit } from "../core/visit.js"; import * as schemas from "./schemas.js"; /** Mini counterpart of `classic/deep-partial.ts`'s `DeepPartial`. */ // biome-ignore format: preserve vertical layout for readability. export type DeepPartial = T extends schemas.ZodMiniObject ? schemas.ZodMiniObject< { -readonly [K in keyof Shape]: schemas.ZodMiniOptional> }, Config > : T extends schemas.ZodMiniDiscriminatedUnion ? schemas.ZodMiniUnion< { -readonly [I in keyof Options]: Options[I] extends core.SomeType ? DeepPartial : Options[I] } > : T extends schemas.ZodMiniUnion ? schemas.ZodMiniUnion< { -readonly [I in keyof Options]: Options[I] extends core.SomeType ? DeepPartial : Options[I] } > : T extends schemas.ZodMiniArray ? schemas.ZodMiniArray> : T extends schemas.ZodMiniTuple ? schemas.ZodMiniTuple< { -readonly [K in keyof Items]: Items[K] extends core.SomeType ? DeepPartial : Items[K] }, Rest extends core.SomeType ? DeepPartial : Rest > : T extends schemas.ZodMiniIntersection ? schemas.ZodMiniIntersection, DeepPartial> : T extends schemas.ZodMiniRecord ? schemas.ZodMiniRecord> : T extends schemas.ZodMiniMap ? schemas.ZodMiniMap> : T extends schemas.ZodMiniSet ? schemas.ZodMiniSet> : T extends schemas.ZodMiniOptional ? schemas.ZodMiniOptional> : T extends schemas.ZodMiniNullable ? schemas.ZodMiniNullable> : T extends schemas.ZodMiniDefault ? schemas.ZodMiniDefault> : T extends schemas.ZodMiniPrefault ? schemas.ZodMiniPrefault> : T extends schemas.ZodMiniNonOptional ? schemas.ZodMiniNonOptional> : T extends schemas.ZodMiniCatch ? schemas.ZodMiniCatch> : T extends schemas.ZodMiniReadonly ? schemas.ZodMiniReadonly> : T extends schemas.ZodMiniSuccess ? schemas.ZodMiniSuccess> : T extends schemas.ZodMiniPromise ? schemas.ZodMiniPromise> // Must precede ZodMiniPipe, which it extends structurally. : T extends schemas.ZodMiniCodec ? schemas.ZodMiniCodec, DeepPartial> : T extends schemas.ZodMiniPipe ? schemas.ZodMiniPipe, DeepPartial> : T extends schemas.ZodMiniLazy ? schemas.ZodMiniLazy> : T; /** See `classic/deep-partial.ts`. Mini variant uses `mini.partial(...)`. */ export function deepPartial(schema: T): DeepPartial { return visit(schema, { object: (s) => schemas.partial(s as schemas.ZodMiniObject), // See `classic/deep-partial.ts`. union: (s) => { const def = s._zod.def as core.$ZodDiscriminatedUnionDef; return def.discriminator === undefined ? s : schemas.union(def.options as schemas.ZodMiniType[]); }, }) as unknown as DeepPartial; }