The Zod schema type
The Zod schema to make deeply partial
A new Zod schema where all properties are optional at all levels
import { z } from "zod";
import { zodDeepPartial } from "zod-deep-partial";
const userSchema = z.object({
name: z.string(),
email: z.string().email(),
profile: z.object({
bio: z.string(),
avatar: z.string().url(),
}),
});
const partialUserSchema = zodDeepPartial(userSchema);
// All of these are now valid:
partialUserSchema.parse({});
partialUserSchema.parse({ name: "John" });
partialUserSchema.parse({ profile: { bio: "Developer" } });
Recursively makes all properties in a Zod schema optional at all levels.
This is the main entry point for creating deeply partial Zod schemas. It transforms a Zod schema so that every property, at every level of nesting, becomes optional. This is useful for:
The function preserves type safety and works with all Zod schema types including: