zod-deep-partial is a lightweight utility package designed to recursively make all properties within a given Zod schema optional. The package is currently at version 1.4.4 and is actively maintained, indicated by recent updates to support Zod v4 and ongoing development on its GitHub repository. Its primary differentiator from Zod's native `.partial()` method is its deep, recursive application of optionality, making it ideal for scenarios like patch updates or handling partially complete data structures. It boasts comprehensive support for a wide array of Zod types, including nested objects, arrays, unions, discriminated unions, intersections, and various transformations, all while maintaining Zod's robust type inference. Crucially, `zod-deep-partial` maintains a minimal footprint by having zero direct dependencies, relying solely on `zod` as a peer dependency.
npm install zod-deep-partialVerified import paths — ran on the pinned version, not inferred.
This quickstart defines a complex Zod schema including primitives, objects, arrays, records, and dates. It then demonstrates how `zodDeepPartial` recursively applies optionality to all properties, showcasing various valid partial inputs and verifying that type inference is correctly preserved, while also illustrating how underlying type validations (like email format) still apply if the property is provided.
Upgrade your project to Zod v4 if possible, ensuring all Zod-related libraries are compatible. If upgrading Zod is not feasible, downgrade `zod-deep-partial` to a version compatible with Zod v3 (e.g., `npm install zod-deep-partial@1.1.0`). Consult Zod's official migration guide for details on updating from Zod v3 to v4.
For recursive optionality, always use `zodDeepPartial`. Use Zod's built-in `schema.partial()` only when you intend to make only the top-level properties optional.
Ensure that if an optional property is provided in the input data, it still adheres to the underlying Zod type definition. `zodDeepPartial` loosens the *presence* requirement, not the *type validity* requirement.
Ensure you are using ES module `import` syntax (`import { zodDeepPartial } from 'zod-deep-partial';`) in an environment that supports it. If you must use CommonJS, ensure proper interoperability or transpile your code, or try `const { zodDeepPartial } = require('zod-deep-partial');`.Review your original Zod schema for any `.nonoptional()` or `.required()` calls that might override the deep partial behavior. If the issue persists with basic types, check for a compatibility issue with your `zod` version and `zod-deep-partial` version.