@zod/mini
The @zod/mini
library was introduced with the release of Zod 4.
It implements the exact same functionality as zod
, but using a functional, tree-shakable API. If you're coming from zod
, this means you generally will use functions in place of methods.
Tree-shaking — In zod
, schemas provide a range of convenience methods to perform some common operations (e.g. .min()
on string schemas). Bundlers have a hard time removing ("tree shaking") method implementations from your bundle, even if they aren't used. It's much easier to remove an unused top-level function, which is why the API of @zod/mini
uses more functions than methods.
ZodMiniType
All @zod/mini
schemas extend the z.ZodMiniType
base class, which in turn extends z.core.$ZodType
from @zod/core
. While this class implements far fewer methods than ZodType
in zod
, some particularly useful methods remain.
.parse
This is an obvious one. All @zod/mini
schemas implement the same parsing methods as zod
.
.check()
In zod
there are dedicated methods on schema subclasses for performing common checks:
In @zod/mini
such methods aren't implemented. Instead you pass these checks into schemas using the .check()
method:
The following checks are implemented. Some of these checks only apply to schemas of certain types (e.g. strings or numbers). The APIs are all type-safe; TypeScript won't let you add an unsupported check to your schema.
.register()
For registering a schema in a registry.
.brand()
For branding a schema. Refer to the Branded types docs for more information.
.clone(def)
Returns an identical clone of the current schema using the provided def
.
No default locale
While zod
automatically loads the English (en
) locale, @zod/mini
does not. This reduces the bundle size in scenarios where error messages are unnecessary, localized to a non-English language, or otherwise customized.
This means, by default the message
property of all issues will simply read "Invalid input"
. To load the English locale:
Refer to the Locales docs for more on localization.