TypeScript-first schema validation with static type inference
z.any()
which accepts
any
type and then add more strict validations later.schema
property of the customEvent
function), we’ll do the second and third steps for you.
undefined
or null
:
null
, you can use nullable()
:
string
from an API and want to convert it to a JavaScript Date
object:
partial()
:
passthrough()
:
strict()
to make the schema throw an error if there are any extra properties:
extends()
and merge()
:
pick()
and omit()
to create a new schema that only includes or excludes certain properties:
z.array()
:
z.tuple()
:
z.union()
:
z.record()
, useful for when you have a map of values but don’t care about the keys: