Skip to content

Commit

Permalink
Add nullableInput
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBarre committed May 17, 2022
1 parent d506b08 commit 1dfbbf9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions deno/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ export abstract class ZodType<
this.superRefine = this.superRefine.bind(this);
this.optional = this.optional.bind(this);
this.nullable = this.nullable.bind(this);
this.nullableInput = this.nullableInput.bind(this);
this.nullish = this.nullish.bind(this);
this.array = this.array.bind(this);
this.promise = this.promise.bind(this);
Expand All @@ -382,6 +383,11 @@ export abstract class ZodType<
nullable(): ZodNullable<this> {
return ZodNullable.create(this) as any;
}
nullableInput(
message?: string | CustomErrorParams | ((arg: Output) => CustomErrorParams)
): ZodType<this["_output"], ZodNullableDef<this>, this["_input"] | null> {
return this.refine((v) => v !== null, message) as any;
}
nullish(): ZodNullable<ZodOptional<this>> {
return this.optional().nullable();
}
Expand Down
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ export abstract class ZodType<
this.superRefine = this.superRefine.bind(this);
this.optional = this.optional.bind(this);
this.nullable = this.nullable.bind(this);
this.nullableInput = this.nullableInput.bind(this);
this.nullish = this.nullish.bind(this);
this.array = this.array.bind(this);
this.promise = this.promise.bind(this);
Expand All @@ -382,6 +383,11 @@ export abstract class ZodType<
nullable(): ZodNullable<this> {
return ZodNullable.create(this) as any;
}
nullableInput(
message?: string | CustomErrorParams | ((arg: Output) => CustomErrorParams)
): ZodType<this["_output"], ZodNullableDef<this>, this["_input"] | null> {
return this.refine((v) => v !== null, message) as any;
}
nullish(): ZodNullable<ZodOptional<this>> {
return this.optional().nullable();
}
Expand Down

0 comments on commit 1dfbbf9

Please sign in to comment.