@cleverbrush/schema vs Zod

Zod is the industry standard for TypeScript schema validation — battle-tested, widely supported, and API-compatible with most ecosystem tooling. @cleverbrush/schema was designed with Zod as a reference point: the primitives and fluent builder style are intentionally familiar so migration is incremental.

Where they differ is in areas Zod never tackled: typed field-error selectors, runtime schema introspection, and a first-class extension system.

Key differences at a glance

Capability@cleverbrush/schemaZod 3/4Notes
TypeScript type inferenceInferType<> vs z.infer<>
Fluent / chainable APINearly identical call sites
Immutable schemasBoth return a new instance on every method
Zero runtime dependenciesBoth have no external deps
Bundle size (gzipped full)~15 KB~14 KB (v3) / ~6 KB (v4)Tree-shakeable — single builder entry points as small as ~4 KB
Validation speed (array of 100 objects)34 K ops/s17 K ops/s~2× faster in benchmarks
Standard Schema v1Both work with TanStack Form, T3 Env, etc.
Custom error messagesIdentical capability
Default valuesIdentical: .default(value) or factory fn
Branded typesIdentical API
Readonly schemasIdentical API
Typed field-error selectorsresult.getErrorsFor(u => u.field) — typos caught at compile time
Runtime schema introspection~.introspect() returns a typed stable descriptor tree; Zod exposes internals via ._def / ._zod.def (undocumented, unstable API)
PropertyDescriptors / metadataPer-field labels, descriptions, metadata
JSDoc comment preservationCarry JSDoc through to form labels and JSON Schema
Type-safe extension systemlimitedAdd typed methods to builders; Zod only has .refine()
extern() — Standard Schema interopWrap any Standard Schema v1 library (incl. Zod) as a property
Per-property error inspectionpath-basedZod uses string/index paths; cleverbrush uses typed lambda selectors
Sync + async validationIdentical capability
z.tuple([...])Use tuple([...])
z.record(key, value)Use record(string(), value)
z.map() / z.set()Use any().hasType(Map) / any().hasType(Set) with preprocessors or custom validators

▶ Full Zod → @cleverbrush/schema migration guide

Comparison with other validation libraries

How does @cleverbrush/schema compare to broader alternatives?

Feature@cleverbrush/schemaZodYupJoi
TypeScript type inference~
Immutable schemas
Zero dependencies
Runtime introspection~~
PropertyDescriptors~
JSDoc comments preservation
Custom error messages
Per-property error inspection~~~
Sync + async validation
Standard Schema v1
Extension / plugin system~~
External schema interop (extern())
Built-in validators (email…)
Default values