Partial updates
Validate PATCH or update payloads where any nested field may be omitted.
Zod · Module
z.deepPartial() recursively makes properties optional throughout a Zod schema. Unlike .partial(), it can traverse nested structures such as objects, arrays, tuples, unions, records, and wrappers.
Pass a Zod schema to z.deepPartial() to recursively make properties optional throughout supported nested structures. The resulting schema still validates supplied values and can be used like other Zod object schemas, including parsing partial nested objects.
z.deepPartial(schema)| Name | Type | Description |
|---|---|---|
schema | Zod schema | The Zod schema whose nested properties should be made optional recursively. |
A transformed Zod schema; for an object input, the result is still a ZodObject with recursively optional properties.
import { z } from "zod";
const Post = z.object({
title: z.string(),
author: z.object({ name: z.string(), email: z.string() }),
});
const PartialPost = z.deepPartial(Post);
PartialPost.parse({ author: {} });Creates a schema in which nested object properties can be omitted while validating the supplied values.
Validate PATCH or update payloads where any nested field may be omitted.
Accept incomplete nested configuration while preserving the original validation rules for supplied values.
Derive a recursively optional form of an existing object schema instead of duplicating its shape.
z.deepPartial() accepts an existing Zod schema and returns a schema whose nested properties are optional recursively. For example, a nested author object can be validated with only the properties that are present.
Follow-up: How does it differ from .partial()? .partial() changes only the top-level shape, while z.deepPartial() continues through supported nested structures.
It can recurse through objects, arrays, tuples, unions, records, and wrappers. This makes it suitable for validating partially supplied data whose structure contains several nested schema types.
Follow-up: What limitation should be checked in older documentation? Older method-based documentation described narrower support, so the current API page should be preferred for the stable major version.
The result remains a ZodObject when applied to the documented object example. Therefore, object-specific APIs such as .shape and .extend() remain available on the result.
Follow-up: What practical benefit follows from retaining ZodObject? A partial schema can still be inspected or extended without converting it to an unrelated schema type.
z.partial()z.object()ZodObject.shapeZodObject.extend()