Partial updates
Accepting PATCH-style payloads where any user field may be updated.
Zod · Module
.partial() derives a Zod object schema with optional properties. Use it without arguments for all fields, or provide a mask to make only selected fields optional.
Use .partial() on a Zod object to derive another object schema whose properties are optional. Call it without arguments to make every property optional, or pass a shape of boolean flags to limit optionality to selected keys.
schema.partial(mask?)| Name | Type | Description |
|---|---|---|
mask | Partial<Record<keyof Shape, true>> | Optional shape whose true-valued keys identify the object properties to make optional. |
A new Zod object schema with all properties optional, or with only the properties selected by the mask optional.
.partial() returns a new object schema with optional properties, either for all fields or for a selected subset.Partial utility type..partial() with no arguments makes every property in the object schema optional..partial() like other supported object-shape operations.import { z } from "zod";
const User = z.object({
email: z.string().email(),
username: z.string(),
});
const UserPatch = User.partial({ username: true });
console.log(UserPatch.parse({ email: "a@example.com" }));Creates a schema for updates where only the selected username field becomes optional.
Accepting PATCH-style payloads where any user field may be updated.
Reusing a required creation schema for a form whose fields are progressively completed.
Allowing a subset of configuration values while retaining required defaults or identifiers.
.partial() method do?.partial() derives an object schema with optional properties. With no arguments, every property becomes optional; passing a boolean-keyed shape restricts the change to selected fields.
Follow-up: How would you model a partial record? Use z.partialRecord(); the documentation recommends it for partial record types.
Call .partial({ fieldName: true }) to make only the named fields optional while leaving the other fields required. The returned schema is still an object schema and can be parsed normally.
Follow-up: What happens when a requested partial key is not declared? The documentation states that undeclared symbol keys are ignored; for ordinary object keys, use keys from the schema shape.
.partial() the same as a deep partial?.partial() is modeled after TypeScript's Partial utility and changes optionality at the object-property level. It does not mean that nested object properties automatically become optional.
Follow-up: What API should be considered when nested structures also need optional fields? Check the documentation for the appropriate deep-partial facility rather than assuming .partial() recurses.
z.objectz.partialRecordz.pickz.omitz.extendz.exactPartial