ZodReadonly
This release introduces ZodReadonly
and the .readonly()
method on ZodType
.
Calling .readonly()
on any schema returns a ZodReadonly
instance that wraps the original schema. The new schema parses all inputs using the original schema, then calls Object.freeze()
on the result. The inferred type is also marked as readonly
.
const schema = z.object({ name: string }).readonly();
type schema = z.infer<typeof schema>;
// Readonly<{name: string}>
const result = schema.parse({ name: "fido" });
result.name = "simba"; // error
The inferred type uses TypeScript's built-in readonly types when relevant.
z.array(z.string()).readonly();
// readonly string[]
z.tuple([z.string(), z.number()]).readonly();
// readonly [string, number]
z.map(z.string(), z.date()).readonly();
// ReadonlyMap<string, Date>
z.set(z.string()).readonly();
// ReadonlySet<Promise<string>>
Commits:
- 6dad907 Comments
- 56ace68 Fix deno test
- 3809d54 Add superforms
- d1ad522 Add transloadit
- a3bb701 Testing on Typescript 5.0 (#2221)
- 51e14be docs: update deprecated link (#2219)
- a263814 fixed Datetime & IP TOC links
- 502384e docs: add mobx-zod-form to form integrations (#2299)
- a8be450 docs: Add
zocker
to Ecosystem section (#2416) - 15de22a Allow subdomains and hyphens in
ZodString.email
(#2274) - 00f5783 Add
zod-openapi
to ecosystem (#2434) - 0a17340 docs: fix minor typo (#2439)
- 60a2134 Add masterborn
- 0a90ed1 chore: move
exports.types
field to first spot @ package.json. (#2443) - 67f35b1 docs: allow Zod to be used in dev tools at site (#2432)
- 6795c57 Fix not working Deno doc link. (#2428)
- 37e9c55 Generalize uuidRegex
- 0969950 adds ctx to preprocess (#2426)
- af08390 fix: super refinement function types (#2420)
- 36fef58 Make email regex reasonable (#2157)
- f627d14 Document canary
- e06321c docs: add tapiduck to API libraries (#2410)
- 11e507c docs: add ts as const example in zod enums (#2412)
- 5427565 docs: add zod-fixture to mocking ecosystem (#2409)
- d3bf7e6 docs: add
zodock
to mocking ecosystem (#2394) - 2270ae5 remove "as any" casts in createZodEnum (#2332)
- 00bdd0a fix proto pollution vulnerability (#2239)
- a3c5256 Fix error_handling unrecognized_keys example
- 4f75cbc Adds getters to Map for key + value (#2356)
- ca7b032 FMC (#2346)
- 6fec8bd docs: fix typo in link fragment (#2329)
- 16f90bd Update README.md
- 2c80250 Update readme
- eaf64e0 Update sponsors
- c576311 Update readme
- 5e23b4f Add
*.md
pattern to prettier (#2476) - 898dced Revamp tests
- 6309322 Update test runners
- c0aece1 Add vitest config
- 73a5610 Update script
- 8d8e1a2 Fix deno test bug
- 9eb2508 Clean up configs
- cfbc7b3 Fix root jest config
- 8677f68 docs(comparison-yup): Yup added partial() and deepPartial() in v1 (#2603)
- fb00edd docs: add VeeValidate form library for Vue.js (#2578)
- ab8e717 docs: fix typo in z.object (#2570)
- d870407 docs: fix incomplete Records example (#2579)
- 5adae24 docs: add conform form integration (#2577)
- 8b8ab3e Update README.md (#2562)
- 6aab901 fix typo test name (#2542)
- 81a89f5 Update nullish documentation to correct chaining order (#2457)
- 78a4090 docs: update comparison with
runtypes
(#2536) - 1ecd624 Fix prettier
- 981d4b5 Add ZodReadonly (#2634)
- fba438c 3.22.0