diff --git a/deno/lib/types.ts b/deno/lib/types.ts index 6ed30845a..4201571a7 100644 --- a/deno/lib/types.ts +++ b/deno/lib/types.ts @@ -571,10 +571,11 @@ export type ZodStringCheck = | { kind: "ip"; version?: IpVersion; message?: string } | { kind: "base64"; message?: string }; -export interface ZodStringDef extends ZodTypeDef { +export interface ZodStringDef + extends ZodTypeDef { checks: ZodStringCheck[]; typeName: ZodFirstPartyTypeKind.ZodString; - coerce: boolean; + coerce: TCoerce; } const cuidRegex = /^c[^\s-]{8,}$/i; @@ -677,7 +678,7 @@ function isValidIP(ip: string, version?: IpVersion) { export class ZodString extends ZodType< string, - ZodStringDef, + ZodStringDef, TCoerce extends true ? unknown : string > { _parse(input: ParseInput): ParseReturnType { @@ -1237,7 +1238,7 @@ export class ZodString extends ZodType< return new ZodString({ checks: [], typeName: ZodFirstPartyTypeKind.ZodString, - coerce: params?.coerce ?? false, + coerce: params?.coerce ?? (false as any), // TODO remove need for 'as any' ...processCreateParams(params), }); }; @@ -1267,15 +1268,16 @@ function floatSafeRemainder(val: number, step: number) { return (valInt % stepInt) / Math.pow(10, decCount); } -export interface ZodNumberDef extends ZodTypeDef { +export interface ZodNumberDef + extends ZodTypeDef { checks: ZodNumberCheck[]; typeName: ZodFirstPartyTypeKind.ZodNumber; - coerce: boolean; + coerce: TCoerce; } export class ZodNumber extends ZodType< number, - ZodNumberDef, + ZodNumberDef, TCoerce extends true ? unknown : number > { _parse(input: ParseInput): ParseReturnType { @@ -1373,7 +1375,7 @@ export class ZodNumber extends ZodType< return new ZodNumber({ checks: [], typeName: ZodFirstPartyTypeKind.ZodNumber, - coerce: params?.coerce || false, + coerce: params?.coerce ?? (false as any), // TODO remove need for 'as any' ...processCreateParams(params), }); }; @@ -1556,15 +1558,16 @@ export type ZodBigIntCheck = | { kind: "max"; value: bigint; inclusive: boolean; message?: string } | { kind: "multipleOf"; value: bigint; message?: string }; -export interface ZodBigIntDef extends ZodTypeDef { +export interface ZodBigIntDef + extends ZodTypeDef { checks: ZodBigIntCheck[]; typeName: ZodFirstPartyTypeKind.ZodBigInt; - coerce: boolean; + coerce: TCoerce; } export class ZodBigInt extends ZodType< bigint, - ZodBigIntDef, + ZodBigIntDef, TCoerce extends true ? unknown : bigint > { _parse(input: ParseInput): ParseReturnType { @@ -1640,7 +1643,7 @@ export class ZodBigInt extends ZodType< return new ZodBigInt({ checks: [], typeName: ZodFirstPartyTypeKind.ZodBigInt, - coerce: params?.coerce ?? false, + coerce: params?.coerce ?? (false as any), // TODO remove need for 'as any' ...processCreateParams(params), }); }; @@ -1762,14 +1765,15 @@ export class ZodBigInt extends ZodType< ////////// /////////// ////////////////////////////////////////// ////////////////////////////////////////// -export interface ZodBooleanDef extends ZodTypeDef { +export interface ZodBooleanDef + extends ZodTypeDef { typeName: ZodFirstPartyTypeKind.ZodBoolean; - coerce: boolean; + coerce: TCoerce; } export class ZodBoolean extends ZodType< boolean, - ZodBooleanDef, + ZodBooleanDef, TCoerce extends true ? unknown : boolean > { _parse(input: ParseInput): ParseReturnType { @@ -1795,7 +1799,7 @@ export class ZodBoolean extends ZodType< ): ZodBoolean => { return new ZodBoolean({ typeName: ZodFirstPartyTypeKind.ZodBoolean, - coerce: params?.coerce || false, + coerce: params?.coerce ?? (false as any), // TODO remove need for 'as any' ...processCreateParams(params), }); }; @@ -1811,15 +1815,16 @@ export class ZodBoolean extends ZodType< export type ZodDateCheck = | { kind: "min"; value: number; message?: string } | { kind: "max"; value: number; message?: string }; -export interface ZodDateDef extends ZodTypeDef { +export interface ZodDateDef + extends ZodTypeDef { checks: ZodDateCheck[]; - coerce: boolean; + coerce: TCoerce; typeName: ZodFirstPartyTypeKind.ZodDate; } export class ZodDate extends ZodType< Date, - ZodDateDef, + ZodDateDef, TCoerce extends true ? unknown : Date > { _parse(input: ParseInput): ParseReturnType { @@ -1937,7 +1942,7 @@ export class ZodDate extends ZodType< ): ZodDate => { return new ZodDate({ checks: [], - coerce: params?.coerce || false, + coerce: params?.coerce ?? (false as any), // TODO remove need for 'as any' typeName: ZodFirstPartyTypeKind.ZodDate, ...processCreateParams(params), }); diff --git a/src/types.ts b/src/types.ts index 668e91f78..f6090a0c5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -571,10 +571,11 @@ export type ZodStringCheck = | { kind: "ip"; version?: IpVersion; message?: string } | { kind: "base64"; message?: string }; -export interface ZodStringDef extends ZodTypeDef { +export interface ZodStringDef + extends ZodTypeDef { checks: ZodStringCheck[]; typeName: ZodFirstPartyTypeKind.ZodString; - coerce: boolean; + coerce: TCoerce; } const cuidRegex = /^c[^\s-]{8,}$/i; @@ -677,7 +678,7 @@ function isValidIP(ip: string, version?: IpVersion) { export class ZodString extends ZodType< string, - ZodStringDef, + ZodStringDef, TCoerce extends true ? unknown : string > { _parse(input: ParseInput): ParseReturnType { @@ -1237,7 +1238,7 @@ export class ZodString extends ZodType< return new ZodString({ checks: [], typeName: ZodFirstPartyTypeKind.ZodString, - coerce: params?.coerce ?? false, + coerce: params?.coerce ?? (false as any), // TODO remove need for 'as any' ...processCreateParams(params), }); }; @@ -1267,15 +1268,16 @@ function floatSafeRemainder(val: number, step: number) { return (valInt % stepInt) / Math.pow(10, decCount); } -export interface ZodNumberDef extends ZodTypeDef { +export interface ZodNumberDef + extends ZodTypeDef { checks: ZodNumberCheck[]; typeName: ZodFirstPartyTypeKind.ZodNumber; - coerce: boolean; + coerce: TCoerce; } export class ZodNumber extends ZodType< number, - ZodNumberDef, + ZodNumberDef, TCoerce extends true ? unknown : number > { _parse(input: ParseInput): ParseReturnType { @@ -1373,7 +1375,7 @@ export class ZodNumber extends ZodType< return new ZodNumber({ checks: [], typeName: ZodFirstPartyTypeKind.ZodNumber, - coerce: params?.coerce || false, + coerce: params?.coerce ?? (false as any), // TODO remove need for 'as any' ...processCreateParams(params), }); }; @@ -1556,15 +1558,16 @@ export type ZodBigIntCheck = | { kind: "max"; value: bigint; inclusive: boolean; message?: string } | { kind: "multipleOf"; value: bigint; message?: string }; -export interface ZodBigIntDef extends ZodTypeDef { +export interface ZodBigIntDef + extends ZodTypeDef { checks: ZodBigIntCheck[]; typeName: ZodFirstPartyTypeKind.ZodBigInt; - coerce: boolean; + coerce: TCoerce; } export class ZodBigInt extends ZodType< bigint, - ZodBigIntDef, + ZodBigIntDef, TCoerce extends true ? unknown : bigint > { _parse(input: ParseInput): ParseReturnType { @@ -1640,7 +1643,7 @@ export class ZodBigInt extends ZodType< return new ZodBigInt({ checks: [], typeName: ZodFirstPartyTypeKind.ZodBigInt, - coerce: params?.coerce ?? false, + coerce: params?.coerce ?? (false as any), // TODO remove need for 'as any' ...processCreateParams(params), }); }; @@ -1762,14 +1765,15 @@ export class ZodBigInt extends ZodType< ////////// /////////// ////////////////////////////////////////// ////////////////////////////////////////// -export interface ZodBooleanDef extends ZodTypeDef { +export interface ZodBooleanDef + extends ZodTypeDef { typeName: ZodFirstPartyTypeKind.ZodBoolean; - coerce: boolean; + coerce: TCoerce; } export class ZodBoolean extends ZodType< boolean, - ZodBooleanDef, + ZodBooleanDef, TCoerce extends true ? unknown : boolean > { _parse(input: ParseInput): ParseReturnType { @@ -1795,7 +1799,7 @@ export class ZodBoolean extends ZodType< ): ZodBoolean => { return new ZodBoolean({ typeName: ZodFirstPartyTypeKind.ZodBoolean, - coerce: params?.coerce || false, + coerce: params?.coerce ?? (false as any), // TODO remove need for 'as any' ...processCreateParams(params), }); }; @@ -1811,15 +1815,16 @@ export class ZodBoolean extends ZodType< export type ZodDateCheck = | { kind: "min"; value: number; message?: string } | { kind: "max"; value: number; message?: string }; -export interface ZodDateDef extends ZodTypeDef { +export interface ZodDateDef + extends ZodTypeDef { checks: ZodDateCheck[]; - coerce: boolean; + coerce: TCoerce; typeName: ZodFirstPartyTypeKind.ZodDate; } export class ZodDate extends ZodType< Date, - ZodDateDef, + ZodDateDef, TCoerce extends true ? unknown : Date > { _parse(input: ParseInput): ParseReturnType { @@ -1937,7 +1942,7 @@ export class ZodDate extends ZodType< ): ZodDate => { return new ZodDate({ checks: [], - coerce: params?.coerce || false, + coerce: params?.coerce ?? (false as any), // TODO remove need for 'as any' typeName: ZodFirstPartyTypeKind.ZodDate, ...processCreateParams(params), });