Skip to content

Commit d4faf71

Browse files
authored
Add v3 docs (#4972)
* Add v3 docs * Tweak
1 parent e32d99b commit d4faf71

32 files changed

+10162
-0
lines changed

packages/docs-v3/.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Unix-style newlines with a newline ending every file
7+
[*]
8+
end_of_line = lf
9+
insert_final_newline = true
10+
indent_style = space
11+
indent_size = 2
12+
charset = utf-8

packages/docs-v3/CHANGELOG.md

Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
# Changelog
2+
3+
## Release notes are now stored in Github Releases: https://github.com/colinhacks/zod/releases
4+
5+
## Previous Releases
6+
7+
### 3.10
8+
9+
- New parser that allows parsing to continue after non-fatal errors have occurred. This allows Zod to surface more errors to the user at once.
10+
11+
### 3.9
12+
13+
- Custom error messages in schemas
14+
15+
```ts
16+
const name = z.string({
17+
invalid_type_error: "Name must be string",
18+
required_error: "Name is required",
19+
});
20+
```
21+
22+
Under the hood, this creates a custom error map that's bound to the schema. You can also pass a custom error map explicitly.
23+
24+
```ts
25+
const name = z.string({ errorMap: myErrorMap });
26+
```
27+
28+
- Rest parameters for tuples
29+
30+
```ts
31+
const myTuple = z.tuple([z.string(), z.number()]).rest(z.boolean());
32+
type t1 = z.output<typeof myTuple>; // [string, number, ...boolean[]]
33+
```
34+
35+
- Selective `.partial`
36+
37+
You can specify certain fields to make optional with the `ZodObject.partial` method.
38+
39+
```ts
40+
const user = z.object({
41+
name: z.string(),
42+
age: z.number(),
43+
});
44+
45+
const optionalNameUser = user.partial({ name: true });
46+
// { name?: string; age: number; }
47+
```
48+
49+
- Specify key schema in ZodRecord
50+
51+
Previously, `z.record` only accepted a single schema:
52+
53+
```ts
54+
z.record(z.boolean()); // Record<string, boolean>;
55+
```
56+
57+
Now `z.record` has been overloaded to support two schemas. The first validates the _keys_ of the record, and the second validates the _values_.
58+
59+
```ts
60+
const schema = z.record(z.number(), z.boolean());
61+
type schema = z.infer<typeof schema>; // Record<number, boolean>
62+
63+
const schema = z.record(z.enum(["Tuna", "Trout"]), z.boolean());
64+
type schema = z.infer<typeof schema>; // Record<"Tuna" | "Trout", boolean>
65+
```
66+
67+
### 3.8
68+
69+
- Add `z.preprocess`
70+
- Implement CUID validation on ZodString (`z.string().cuid()`)
71+
- Improved `.deepPartial()`: now recursively operates on arrays, tuples, optionals, and nullables (in addition to objects)
72+
73+
### 3.7
74+
75+
- Eliminate `ZodNonEmptyArray`, add `Cardinality` to `ZodArray`
76+
- Add optional error message to `ZodArray.nonempty`
77+
- Add `.gt/.gte/.lt/.lte` to `ZodNumber`
78+
79+
### 3.6
80+
81+
- Add IE11 support
82+
- `ZodError.flatten` now optionally accepts a map function for customizing the output
83+
- `.void()` now only accepts undefined, not null.
84+
- `z.enum` now supports `Readonly` string tuples
85+
86+
### 3.5
87+
88+
- Add discriminator to all first-party schema defs
89+
90+
### 3.4
91+
92+
- `unknown` and `any` schemas are always interpreted as optional. Reverts change from 3.3.
93+
94+
### 3.3
95+
96+
- HUGE speed improvements
97+
- Added benchmarking: `yarn benchmark`
98+
- Type signature of `ZodType#_parse` has changed. This will affects users who have implemented custom subclasses of `ZodType`.
99+
- [reverted] Object fields of type `unknown` are no longer inferred as optional.
100+
101+
### 3.2
102+
103+
- Certain methods (`.or`, `.transform`) now return a new instance that wrap the current instance, instead of trying to avoid additional nesting. For example:
104+
105+
```ts
106+
z.union([z.string(), z.number()]).or(z.boolean());
107+
// previously
108+
// => ZodUnion<[ZodString, ZodNumber, ZodBoolean]>
109+
110+
// now
111+
// => ZodUnion<[ZodUnion<[ZodString, ZodNumber]>, ZodBoolean]>
112+
```
113+
114+
This change was made due to recursion limitations in TypeScript 4.3 that made it impossible to properly type these methods.
115+
116+
### 3.0.0-beta.1
117+
118+
- Moved default value logic into ZodDefault. Implemented `.nullish()` method.
119+
120+
### 3.0.0-alpha.33
121+
122+
- Added `.returnType` and `.parameters` methods to ZodFunction
123+
124+
### 3.0.0-alpha.32
125+
126+
- Added `.required()` method to ZodObject
127+
128+
### 3.0.0-alpha.30
129+
130+
- Added Rollup for bundling ESM module
131+
132+
### zod@3.0.0-alpha.24
133+
134+
- Added back ZodIntersection
135+
- Added .and() method to base class
136+
137+
### zod@3.0.0-alpha.9
138+
139+
- Added `z.strictCreate`
140+
141+
### zod@3.0.0-alpha.8
142+
143+
- Allowing optional default values on ZodOptional
144+
145+
### zod@3.0.0-alpha.5
146+
147+
March 17, 2021
148+
149+
- Refactored parsing logic into individual subclass methods
150+
- Eliminated ZodTypes to enable custom ZodType subclasses
151+
- Removed ZodIntersection
152+
- Added ZodEffects as a container for refinement and transform logic
153+
- Added `or` method to `ZodType`
154+
- Added `format` method to `ZodError`
155+
- Added `unwrap` method to `ZodOptional` and `ZodNullable`
156+
- Added new `default` method and moved default functionality into ZodOptional
157+
- Implemented `z.setErrorMap`
158+
- Exporting `z` variable from `index.ts` to enable `import { z } from 'zod';`
159+
160+
### zod@3.0.0-alpha.4
161+
162+
Jan 25, 2021
163+
164+
- New implementation of transformers
165+
- Removed type guards
166+
167+
### zod@2
168+
169+
- Added ZodTransformer
170+
- Async refinements
171+
172+
### zod@1.11
173+
174+
- Introduced `.safeParse` option
175+
- Introduced .regex method on string schemas
176+
- Implemented `.primitives()` and `.nonprimitives()` on object schemas
177+
- Implemented `z.nativeEnum()` for creating schemas from TypeScript `enum`s
178+
- Switched to `new URL()` constructor to check valid URLs
179+
180+
### zod@1.10
181+
182+
- Dropping support for TypeScript 3.2
183+
184+
### zod@1.9
185+
186+
- Added z.instanceof() and z.custom()
187+
- Implemented ZodSchema.array() method
188+
189+
### zod@1.8
190+
191+
- Introduced z.void()
192+
- Major overhaul to error handling system, including the introduction of custom error maps
193+
- Wrote new [error handling guide](./ERROR_HANDLING.md)
194+
195+
### zod@1.7
196+
197+
- Added several built-in validators to string, number, and array schemas
198+
- Calls to `.refine` now return new instance
199+
200+
### zod@1.5
201+
202+
- Introduces ZodAny and ZodUnknown
203+
204+
### zod@1.4
205+
206+
- Refinement types (`.refine`)
207+
- Parsing no longer returns deep clone
208+
209+
### zod@1.3
210+
211+
- Promise schemas
212+
213+
### zod@1.2.6
214+
215+
- `.parse` accepts `unknown`
216+
- `bigint` schemas
217+
218+
### zod@1.2.5
219+
220+
- `.partial` and `.deepPartial` on object schemas
221+
222+
### zod@1.2.3
223+
224+
- Added ZodDate
225+
226+
### zod@1.2.0
227+
228+
- Added `.pick`, `.omit`, and `.extend` on object schemas
229+
230+
### zod@1.1.0
231+
232+
- Added ZodRecord
233+
234+
### zod@1.0.11
235+
236+
- Added `.nonstrict`
237+
238+
### zod@1.0.10
239+
240+
- Added type assertions with `.check`
241+
242+
### zod@1.0.4
243+
244+
- Support for empty tuples
245+
246+
### zod@1.0.2
247+
248+
- Added type assertions
249+
- Added ZodLiteral
250+
- Added ZodEnum
251+
- Improved error reporting
252+
253+
### zod@1.0.0
254+
255+
- Initial release

0 commit comments

Comments
 (0)