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 |
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [email protected] | Added z.instanceof() and z.custom(). Implemented ZodSchema.array() method. |
| [email protected] | 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). |
| [email protected] | Added several built-in validators to string, number, and array schemas. Calls to `.refine` now return new instance. |
| [email protected] | Any and unknown types |
| [email protected] | Refinement types (`.refine`), `.parse` no longer returns deep clone |
| [email protected] | Promise schemas |
| [email protected] | `.parse` accepts `unknown`, `bigint` schemas |
| [email protected] | `.partial` and `.deepPartial` on object schemas |
| [email protected] | Date schemas |
| [email protected] | `.pick`, `.omit`, and `.extend` on object schemas |
| [email protected] | Records |
| [email protected] | `.nonstrict` |
| [email protected] | Type assertions with `.check` |
| [email protected] | Empty tuples |
| [email protected] | Type assertions, literals, enums, detailed error reporting |
| [email protected] | Initial release |
| zod version | release notes |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [email protected] | Added z.instanceof() and z.custom(). Implemented ZodSchema.array() method. |
| [email protected] | 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). |
| [email protected] | Added several built-in validators to string, number, and array schemas. Calls to `.refine` now return new instance. |
| [email protected] | Any and unknown types |
| [email protected] | Refinement types (`.refine`), `.parse` no longer returns deep clone |
| [email protected] | Promise schemas |
| [email protected] | `.parse` accepts `unknown`, `bigint` schemas |
| [email protected] | `.partial` and `.deepPartial` on object schemas |
| [email protected] | Date schemas |
| [email protected] | `.pick`, `.omit`, and `.extend` on object schemas |
| [email protected] | Records |
| [email protected] | `.nonstrict` |
| [email protected] | Type assertions with `.check` |
| [email protected] | Empty tuples |
| [email protected] | Type assertions, literals, enums, detailed error reporting |
| [email protected] | 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.