Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions deno/lib/__tests__/zok.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as z from "../index.ts";

const field = z.Field();
const meesage = z.Field().hi();

test.only("passing validation", () => {
console.log(field, meesage);
});
30 changes: 30 additions & 0 deletions deno/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,9 @@ export interface ZodNumberDef extends ZodTypeDef {
}

export class ZodNumber extends ZodType<number, ZodNumberDef> {
hi() {
console.log("hiiiii");
}
_parse(input: ParseInput): ParseReturnType<number> {
if (this._def.coerce) {
input.data = Number(input.data);
Expand Down Expand Up @@ -1349,6 +1352,31 @@ export class ZodNumber extends ZodType<number, ZodNumberDef> {
}
}

/////////////////////////////////////////
/////////////////////////////////////////
////////// //////////
////////// ZodField //////////
////////// //////////
/////////////////////////////////////////
/////////////////////////////////////////

export class ZodField extends ZodNumber {
static create = (
params?: RawCreateParams & { coerce?: boolean }
): ZodNumber => {
return new ZodField({
checks: [],
typeName: ZodFirstPartyTypeKind.ZodNumber,
coerce: params?.coerce || false,
...processCreateParams(params),
});
};

public hi() {
return "I work : )";
}
}

/////////////////////////////////////////
/////////////////////////////////////////
////////// //////////
Expand Down Expand Up @@ -4926,6 +4954,7 @@ const optionalType = ZodOptional.create;
const nullableType = ZodNullable.create;
const preprocessType = ZodEffects.createWithPreprocess;
const pipelineType = ZodPipeline.create;
const zodFieldType = ZodField.create;
const ostring = () => stringType().optional();
const onumber = () => numberType().optional();
const oboolean = () => booleanType().optional();
Expand Down Expand Up @@ -4955,6 +4984,7 @@ export {
discriminatedUnionType as discriminatedUnion,
effectsType as effect,
enumType as enum,
zodFieldType as Field,
functionType as function,
instanceOfType as instanceof,
intersectionType as intersection,
Expand Down
8 changes: 8 additions & 0 deletions src/__tests__/zok.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as z from "../index";

const field = z.Field();
const meesage = z.Field().hi();

test.only("passing validation", () => {
console.log(field, meesage);
});
30 changes: 30 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,9 @@ export interface ZodNumberDef extends ZodTypeDef {
}

export class ZodNumber extends ZodType<number, ZodNumberDef> {
hi() {
console.log("hiiiii");
}
_parse(input: ParseInput): ParseReturnType<number> {
if (this._def.coerce) {
input.data = Number(input.data);
Expand Down Expand Up @@ -1349,6 +1352,31 @@ export class ZodNumber extends ZodType<number, ZodNumberDef> {
}
}

/////////////////////////////////////////
/////////////////////////////////////////
////////// //////////
////////// ZodField //////////
////////// //////////
/////////////////////////////////////////
/////////////////////////////////////////

export class ZodField extends ZodNumber {
static create = (
params?: RawCreateParams & { coerce?: boolean }
): ZodNumber => {
return new ZodField({
checks: [],
typeName: ZodFirstPartyTypeKind.ZodNumber,
coerce: params?.coerce || false,
...processCreateParams(params),
});
};

public hi() {
return "I work : )";
}
}

/////////////////////////////////////////
/////////////////////////////////////////
////////// //////////
Expand Down Expand Up @@ -4926,6 +4954,7 @@ const optionalType = ZodOptional.create;
const nullableType = ZodNullable.create;
const preprocessType = ZodEffects.createWithPreprocess;
const pipelineType = ZodPipeline.create;
const zodFieldType = ZodField.create;
const ostring = () => stringType().optional();
const onumber = () => numberType().optional();
const oboolean = () => booleanType().optional();
Expand Down Expand Up @@ -4955,6 +4984,7 @@ export {
discriminatedUnionType as discriminatedUnion,
effectsType as effect,
enumType as enum,
zodFieldType as Field,
functionType as function,
instanceOfType as instanceof,
intersectionType as intersection,
Expand Down