diff --git a/deno/lib/__tests__/zok.test.ts b/deno/lib/__tests__/zok.test.ts new file mode 100644 index 0000000000..044af0a4dd --- /dev/null +++ b/deno/lib/__tests__/zok.test.ts @@ -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); +}); \ No newline at end of file diff --git a/deno/lib/types.ts b/deno/lib/types.ts index 13d42a738d..db21987b11 100644 --- a/deno/lib/types.ts +++ b/deno/lib/types.ts @@ -1083,6 +1083,9 @@ export interface ZodNumberDef extends ZodTypeDef { } export class ZodNumber extends ZodType { + hi() { + console.log("hiiiii"); + } _parse(input: ParseInput): ParseReturnType { if (this._def.coerce) { input.data = Number(input.data); @@ -1349,6 +1352,31 @@ export class ZodNumber extends ZodType { } } +///////////////////////////////////////// +///////////////////////////////////////// +////////// ////////// +////////// 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 : )"; + } +} + ///////////////////////////////////////// ///////////////////////////////////////// ////////// ////////// @@ -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(); @@ -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, diff --git a/src/__tests__/zok.test.ts b/src/__tests__/zok.test.ts new file mode 100644 index 0000000000..60fcc7c5e2 --- /dev/null +++ b/src/__tests__/zok.test.ts @@ -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); +}); \ No newline at end of file diff --git a/src/types.ts b/src/types.ts index eb4349c25f..8a68f89094 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1083,6 +1083,9 @@ export interface ZodNumberDef extends ZodTypeDef { } export class ZodNumber extends ZodType { + hi() { + console.log("hiiiii"); + } _parse(input: ParseInput): ParseReturnType { if (this._def.coerce) { input.data = Number(input.data); @@ -1349,6 +1352,31 @@ export class ZodNumber extends ZodType { } } +///////////////////////////////////////// +///////////////////////////////////////// +////////// ////////// +////////// 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 : )"; + } +} + ///////////////////////////////////////// ///////////////////////////////////////// ////////// ////////// @@ -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(); @@ -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,