Basic Usage
Create a schema for JavaScriptMap objects with validated keys and values.
Signature
ZodType
required
Schema to validate all map keys.
ZodType
required
Schema to validate all map values.
string | ZodMapParams
Optional error message (string) or configuration object.
Properties
ZodType
Access the key schema.
ZodType
Access the value schema.
Methods
min()
Set a minimum size for the map.number
required
Minimum number of entries required.
string | object
Optional error message or configuration object.
max()
Set a maximum size for the map.number
required
Maximum number of entries allowed.
string | object
Optional error message or configuration object.
size()
Set an exact size for the map.number
required
Exact number of entries required.
string | object
Optional error message or configuration object.
nonempty()
Require at least one entry (equivalent to.min(1)).
string | object
Optional error message or configuration object.
Complex Types
Object Values
Object Keys
When using object keys, remember that JavaScript uses reference equality. Two objects with the same shape are different keys.
Nested Maps
Type Inference
Common Patterns
Cache Implementation
Entity Store
Adjacency List (Graph)
Refinements
Add custom validation:Map vs Record
Transformations
Transform map data:Related
- z.record() - For plain object key-value pairs
- z.set() - For Set data structures
- z.object() - For fixed object shapes