@@ -571,10 +571,11 @@ export type ZodStringCheck =
571
571
| { kind : "ip" ; version ?: IpVersion ; message ?: string }
572
572
| { kind : "base64" ; message ?: string } ;
573
573
574
- export interface ZodStringDef extends ZodTypeDef {
574
+ export interface ZodStringDef < TCoerce extends boolean = false >
575
+ extends ZodTypeDef {
575
576
checks : ZodStringCheck [ ] ;
576
577
typeName : ZodFirstPartyTypeKind . ZodString ;
577
- coerce : boolean ;
578
+ coerce : TCoerce ;
578
579
}
579
580
580
581
const cuidRegex = / ^ c [ ^ \s - ] { 8 , } $ / i;
@@ -1237,7 +1238,7 @@ export class ZodString<TCoerce extends boolean = false> extends ZodType<
1237
1238
return new ZodString < TParam [ "coerce" ] extends true ? true : false > ( {
1238
1239
checks : [ ] ,
1239
1240
typeName : ZodFirstPartyTypeKind . ZodString ,
1240
- coerce : params ?. coerce ?? false ,
1241
+ coerce : params ?. coerce ?? ( false as any ) , // TODO remove need for 'as any'
1241
1242
...processCreateParams ( params ) ,
1242
1243
} ) ;
1243
1244
} ;
@@ -1267,10 +1268,11 @@ function floatSafeRemainder(val: number, step: number) {
1267
1268
return ( valInt % stepInt ) / Math . pow ( 10 , decCount ) ;
1268
1269
}
1269
1270
1270
- export interface ZodNumberDef extends ZodTypeDef {
1271
+ export interface ZodNumberDef < TCoerce extends boolean = false >
1272
+ extends ZodTypeDef {
1271
1273
checks : ZodNumberCheck [ ] ;
1272
1274
typeName : ZodFirstPartyTypeKind . ZodNumber ;
1273
- coerce : boolean ;
1275
+ coerce : TCoerce ;
1274
1276
}
1275
1277
1276
1278
export class ZodNumber < TCoerce extends boolean = false > extends ZodType <
@@ -1373,7 +1375,7 @@ export class ZodNumber<TCoerce extends boolean = false> extends ZodType<
1373
1375
return new ZodNumber < TParam [ "coerce" ] extends true ? true : false > ( {
1374
1376
checks : [ ] ,
1375
1377
typeName : ZodFirstPartyTypeKind . ZodNumber ,
1376
- coerce : params ?. coerce || false ,
1378
+ coerce : params ?. coerce ?? ( false as any ) , // TODO remove need for 'as any'
1377
1379
...processCreateParams ( params ) ,
1378
1380
} ) ;
1379
1381
} ;
@@ -1556,10 +1558,11 @@ export type ZodBigIntCheck =
1556
1558
| { kind : "max" ; value : bigint ; inclusive : boolean ; message ?: string }
1557
1559
| { kind : "multipleOf" ; value : bigint ; message ?: string } ;
1558
1560
1559
- export interface ZodBigIntDef extends ZodTypeDef {
1561
+ export interface ZodBigIntDef < TCoerce extends boolean = false >
1562
+ extends ZodTypeDef {
1560
1563
checks : ZodBigIntCheck [ ] ;
1561
1564
typeName : ZodFirstPartyTypeKind . ZodBigInt ;
1562
- coerce : boolean ;
1565
+ coerce : TCoerce ;
1563
1566
}
1564
1567
1565
1568
export class ZodBigInt < TCoerce extends boolean = false > extends ZodType <
@@ -1640,7 +1643,7 @@ export class ZodBigInt<TCoerce extends boolean = false> extends ZodType<
1640
1643
return new ZodBigInt < TParam [ "coerce" ] extends true ? true : false > ( {
1641
1644
checks : [ ] ,
1642
1645
typeName : ZodFirstPartyTypeKind . ZodBigInt ,
1643
- coerce : params ?. coerce ?? false ,
1646
+ coerce : params ?. coerce ?? ( false as any ) , // TODO remove need for 'as any'
1644
1647
...processCreateParams ( params ) ,
1645
1648
} ) ;
1646
1649
} ;
@@ -1762,9 +1765,10 @@ export class ZodBigInt<TCoerce extends boolean = false> extends ZodType<
1762
1765
////////// ///////////
1763
1766
//////////////////////////////////////////
1764
1767
//////////////////////////////////////////
1765
- export interface ZodBooleanDef extends ZodTypeDef {
1768
+ export interface ZodBooleanDef < TCoerce extends boolean = false >
1769
+ extends ZodTypeDef {
1766
1770
typeName : ZodFirstPartyTypeKind . ZodBoolean ;
1767
- coerce : boolean ;
1771
+ coerce : TCoerce ;
1768
1772
}
1769
1773
1770
1774
export class ZodBoolean < TCoerce extends boolean = false > extends ZodType <
@@ -1795,7 +1799,7 @@ export class ZodBoolean<TCoerce extends boolean = false> extends ZodType<
1795
1799
) : ZodBoolean < TParam [ "coerce" ] extends true ? true : false > => {
1796
1800
return new ZodBoolean < TParam [ "coerce" ] extends true ? true : false > ( {
1797
1801
typeName : ZodFirstPartyTypeKind . ZodBoolean ,
1798
- coerce : params ?. coerce || false ,
1802
+ coerce : params ?. coerce ?? ( false as any ) , // TODO remove need for 'as any'
1799
1803
...processCreateParams ( params ) ,
1800
1804
} ) ;
1801
1805
} ;
@@ -1811,9 +1815,10 @@ export class ZodBoolean<TCoerce extends boolean = false> extends ZodType<
1811
1815
export type ZodDateCheck =
1812
1816
| { kind : "min" ; value : number ; message ?: string }
1813
1817
| { kind : "max" ; value : number ; message ?: string } ;
1814
- export interface ZodDateDef extends ZodTypeDef {
1818
+ export interface ZodDateDef < TCoerce extends boolean = false >
1819
+ extends ZodTypeDef {
1815
1820
checks : ZodDateCheck [ ] ;
1816
- coerce : boolean ;
1821
+ coerce : TCoerce ;
1817
1822
typeName : ZodFirstPartyTypeKind . ZodDate ;
1818
1823
}
1819
1824
@@ -1937,7 +1942,7 @@ export class ZodDate<TCoerce extends boolean = false> extends ZodType<
1937
1942
) : ZodDate < TParam [ "coerce" ] extends true ? true : false > => {
1938
1943
return new ZodDate < TParam [ "coerce" ] extends true ? true : false > ( {
1939
1944
checks : [ ] ,
1940
- coerce : params ?. coerce || false ,
1945
+ coerce : params ?. coerce ?? ( false as any ) , // TODO remove need for 'as any'
1941
1946
typeName : ZodFirstPartyTypeKind . ZodDate ,
1942
1947
...processCreateParams ( params ) ,
1943
1948
} ) ;
0 commit comments