Skip to content

Commit

Permalink
Removed beta links to error handling guide
Browse files Browse the repository at this point in the history
  • Loading branch information
Colin McDonnell committed Jul 9, 2020
1 parent 5568a74 commit fd21959
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 20 deletions.
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,7 @@ User.omit({ outer: { inner: { prop2: true } } }); // { outer: { prop1: string, i

## Errors

There is a dedicated guide on Zod's error handling system here: [ERROR_HANDLING.md](https://github.com/vriad/zod/blob/beta/ERROR_HANDLING.md)
There is a dedicated guide on Zod's error handling system here: [ERROR_HANDLING.md](https://github.com/vriad/zod/blob/master/ERROR_HANDLING.md)

# Comparison

Expand Down Expand Up @@ -1346,21 +1346,21 @@ If you want to validate function inputs, use function schemas in Zod! It's a muc

# Changelog

| zod version | release notes |
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| zod@1.9 | Added z.instanceof() and z.custom(). Implemented ZodSchema.array() method. |
| zod@1.8 | Introduced z.void(). Major overhaul to error handling system, including the introduction of custom error maps. Wrote new [error handling guide](https://github.com/vriad/zod/blob/beta/ERROR_HANDLING.md). |
| zod@1.7 | Added several built-in validators to string, number, and array schemas. Calls to `.refine` now return new instance. |
| zod@1.5 | Any and unknown types |
| zod@1.4 | Refinement types (`.refine`), `.parse` no longer returns deep clone |
| zod@1.3 | Promise schemas |
| zod@1.2.6 | `.parse` accepts `unknown`, `bigint` schemas |
| zod@1.2.5 | `.partial` and `.deepPartial` on object schemas |
| zod@1.2.3 | Date schemas |
| zod@1.2.0 | `.pick`, `.omit`, and `.extend` on object schemas |
| zod@1.1.0 | Records |
| zod@1.0.11 | `.nonstrict` |
| zod@1.0.10 | Type assertions with `.check` |
| zod@1.0.4 | Empty tuples |
| zod@1.0.0 | Type assertions, literals, enums, detailed error reporting |
| zod@1.0.0 | Initial release |
| zod version | release notes |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| zod@1.9 | Added z.instanceof() and z.custom(). Implemented ZodSchema.array() method. |
| zod@1.8 | Introduced z.void(). Major overhaul to error handling system, including the introduction of custom error maps. Wrote new [error handling guide](https://github.com/vriad/zod/blob/master/ERROR_HANDLING.md). |
| zod@1.7 | Added several built-in validators to string, number, and array schemas. Calls to `.refine` now return new instance. |
| zod@1.5 | Any and unknown types |
| zod@1.4 | Refinement types (`.refine`), `.parse` no longer returns deep clone |
| zod@1.3 | Promise schemas |
| zod@1.2.6 | `.parse` accepts `unknown`, `bigint` schemas |
| zod@1.2.5 | `.partial` and `.deepPartial` on object schemas |
| zod@1.2.3 | Date schemas |
| zod@1.2.0 | `.pick`, `.omit`, and `.extend` on object schemas |
| zod@1.1.0 | Records |
| zod@1.0.11 | `.nonstrict` |
| zod@1.0.10 | Type assertions with `.check` |
| zod@1.0.4 | Empty tuples |
| zod@1.0.0 | Type assertions, literals, enums, detailed error reporting |
| zod@1.0.0 | Initial release |
21 changes: 20 additions & 1 deletion src/playground.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
// import * as z from '.';
// z.date().parse(new Date('invalid'));
// // z.date().parse(new Date('invalid'));

// // const myFunc = z.function(z.tuple([z.string()]), z.boolean()).implement(str => str.length > 5);

// // try {
// // myFunc(12 as any);
// // } catch (err) {
// // console.log(JSON.stringify(err, null, 2));
// // }

// const $Cat = z.object({
// type: z.literal('cat'),
// ability: z.literal('meow'),
// });
// const $Dog = z.object({
// type: z.literal('dog'),
// ability: z.literal('bark'),
// });
// const $AnimalAbility = z.union([$Cat, $Dog]).distribute($A => $A.shape.ability);
// type Ability = z.infer<typeof $AnimalAbility>; // "meow" | "bark"
4 changes: 4 additions & 0 deletions src/types/union.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export class ZodUnion<T extends [z.ZodTypeAny, z.ZodTypeAny, ...z.ZodTypeAny[]]>
options: this._def.options.map(x => x.toJSON()),
});

distribute = <F extends (arg: T[number]) => z.ZodTypeAny>(f: F): ZodUnion<{ [k in keyof T]: ReturnType<F> }> => {
return ZodUnion.create(this._def.options.map(f) as any);
};

static create = <T extends [z.ZodTypeAny, z.ZodTypeAny, ...z.ZodTypeAny[]]>(types: T): ZodUnion<T> => {
return new ZodUnion({
t: z.ZodTypes.union,
Expand Down

0 comments on commit fd21959

Please sign in to comment.