- Add
z.preprocess - Implement CUID validation on ZodString (
z.string().cuid()) - Improved
.deepPartial(): now recursively operates on arrays, tuples, optionals, and nullables (in addition to objects)
- Eliminate
ZodNonEmptyArray, addCardinalitytoZodArray - Add optional error message to
ZodArray.nonempty - Add
.gt/.gte/.lt/.ltetoZodNumber
- Add IE11 support
ZodError.flattennow optionally accepts a map function for customizing the output.void()now only accepts undefined, not null.z.enumnow supportsReadonlystring tuples
- Add discriminator to all first-party schema defs
unknownandanyschemas are always interpreted as optional. Reverts change from 3.3.
- HUGE speed improvements
- Added benchmarking:
yarn benchmark - Type signature of
ZodType#_parsehas changed. This will affects users who have implemented custom subclasses ofZodType. - [reverted] Object fields of type
unknownare no longer inferred as optional.
- Certain methods (
.or,.transform) now return a new instance that wrap the current instance, instead of trying to avoid additional nesting. For example:
z.union([z.string(), z.number()]).or(z.boolean());
// previously
// => ZodUnion<[ZodString, ZodNumber, ZodBoolean]>
// now
// => ZodUnion<[ZodUnion<[ZodString, ZodNumber]>, ZodBoolean]>This change was made due to recursion limitations in TypeScript 4.3 that made it impossible to properly type these methods.
- Moved default value logic into ZodDefault. Implemented
.nullish()method.
- Added
.returnTypeand.parametersmethods to ZodFunction
- Added
.required()method to ZodObject
- Added Rollup for bundling ESM module
- Added back ZodIntersection
- Added .and() method to base class
- Added
z.strictCreate
- Allowing optional default values on ZodOptional
March 17, 2021
- Refactored parsing logic into individual subclass methods
- Eliminated ZodTypes to enable custom ZodType subclasses
- Removed ZodIntersection
- Added ZodEffects as a container for refinement and transform logic
- Added
ormethod toZodType - Added
formatmethod toZodError - Added
unwrapmethod toZodOptionalandZodNullable - Added new
defaultmethod and moved default functionality into ZodOptional - Implemented
z.setErrorMap - Exporting
zvariable fromindex.tsto enableimport { z } from 'zod';
Jan 25, 2021
- New implementation of transformers
- Removed type guards
- Added ZodTransformer
- Async refinements
- Introduced
.safeParseoption - Introduced .regex method on string schemas
- Implemented
.primitives()and.nonprimitives()on object schemas - Implemented
z.nativeEnum()for creating schemas from TypeScriptenums - Switched to
new URL()constructor to check valid URLs
- Dropping support for TypeScript 3.2
- Added z.instanceof() and z.custom()
- Implemented ZodSchema.array() method
- Introduced z.void()
- Major overhaul to error handling system, including the introduction of custom error maps
- Wrote new error handling guide
- Added several built-in validators to string, number, and array schemas
- Calls to
.refinenow return new instance
- Introduces ZodAny and ZodUnknown
- Refinement types (
.refine) - Parsing no longer returns deep clone
- Promise schemas
.parseacceptsunknownbigintschemas
.partialand.deepPartialon object schemas
- Added ZodDate
- Added
.pick,.omit, and.extendon object schemas
- Added ZodRecord
- Added
.nonstrict
- Added type assertions with
.check
- Support for empty tuples
- Added type assertions
- Added ZodLiteral
- Added ZodEnum
- Improved error reporting
- Initial release