Skip to content

Commit

Permalink
Merge branch 'andersk-void'
Browse files Browse the repository at this point in the history
  • Loading branch information
Colin McDonnell committed Aug 1, 2021
2 parents c0f6f62 + be330d2 commit 1409cce
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

### 3.6

- Add IE11 support
- `ZodError.flatten` now optionally accepts a map function for customizing the output
- `.void()` now only accepts undefined, not null.

### 3.5

- Add discriminator to all first-party schema defs
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ z.date();
// empty types
z.undefined();
z.null();
z.void(); // accepts null or undefined
z.void(); // accepts undefined

// catch-all types
// allows any value
Expand Down Expand Up @@ -1112,7 +1112,7 @@ myFunction.returnType();
* `args: ZodTuple` The first argument is a tuple (created with `z.tuple([...])` and defines the schema of the arguments to your function. If the function doesn't accept arguments, you can pass an empty tuple (`z.tuple([])`).
* `returnType: any Zod schema` The second argument is the function's return type. This can be any Zod schema. -->

> You can use the special `z.void()` option if your function doesn't return anything. This will let Zod properly infer the type of void-returning functions. (Void-returning function can actually return either undefined or null.)
> You can use the special `z.void()` option if your function doesn't return anything. This will let Zod properly infer the type of void-returning functions. (Void-returning functions actually return undefined.)
<!--
Expand Down
2 changes: 1 addition & 1 deletion deno/lib/__tests__/void.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { util } from "../helpers/util.ts";
import * as z from "../index.ts";
test("void", () => {
const v = z.void();
v.parse(null);
v.parse(undefined);

expect(() => v.parse(null)).toThrow();
expect(() => v.parse("")).toThrow();

type v = z.infer<typeof v>;
Expand Down
5 changes: 1 addition & 4 deletions deno/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1013,10 +1013,7 @@ export class ZodVoid extends ZodType<void, ZodVoidDef> {
data: any,
parsedType: ZodParsedType
): ParseReturnType<void> {
if (
parsedType !== ZodParsedType.undefined &&
parsedType !== ZodParsedType.null
) {
if (parsedType !== ZodParsedType.undefined) {
ctx.addIssue(data, {
code: ZodIssueCode.invalid_type,
expected: ZodParsedType.void,
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/void.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { util } from "../helpers/util";
import * as z from "../index";
test("void", () => {
const v = z.void();
v.parse(null);
v.parse(undefined);

expect(() => v.parse(null)).toThrow();
expect(() => v.parse("")).toThrow();

type v = z.infer<typeof v>;
Expand Down
5 changes: 1 addition & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1013,10 +1013,7 @@ export class ZodVoid extends ZodType<void, ZodVoidDef> {
data: any,
parsedType: ZodParsedType
): ParseReturnType<void> {
if (
parsedType !== ZodParsedType.undefined &&
parsedType !== ZodParsedType.null
) {
if (parsedType !== ZodParsedType.undefined) {
ctx.addIssue(data, {
code: ZodIssueCode.invalid_type,
expected: ZodParsedType.void,
Expand Down

0 comments on commit 1409cce

Please sign in to comment.