@@ -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;
@@ -677,7 +678,7 @@ function isValidIP(ip: string, version?: IpVersion) {
677
678
678
679
export class ZodString < TCoerce extends boolean = false > extends ZodType <
679
680
string ,
680
- ZodStringDef ,
681
+ ZodStringDef < TCoerce > ,
681
682
TCoerce extends true ? unknown : string
682
683
> {
683
684
_parse ( input : ParseInput ) : ParseReturnType < string > {
@@ -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,15 +1268,16 @@ 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 <
1277
1279
number ,
1278
- ZodNumberDef ,
1280
+ ZodNumberDef < TCoerce > ,
1279
1281
TCoerce extends true ? unknown : number
1280
1282
> {
1281
1283
_parse ( input : ParseInput ) : ParseReturnType < number > {
@@ -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,15 +1558,16 @@ 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 <
1566
1569
bigint ,
1567
- ZodBigIntDef ,
1570
+ ZodBigIntDef < TCoerce > ,
1568
1571
TCoerce extends true ? unknown : bigint
1569
1572
> {
1570
1573
_parse ( input : ParseInput ) : ParseReturnType < bigint > {
@@ -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,14 +1765,15 @@ 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 <
1771
1775
boolean ,
1772
- ZodBooleanDef ,
1776
+ ZodBooleanDef < TCoerce > ,
1773
1777
TCoerce extends true ? unknown : boolean
1774
1778
> {
1775
1779
_parse ( input : ParseInput ) : ParseReturnType < boolean > {
@@ -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,15 +1815,16 @@ 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
1820
1825
export class ZodDate < TCoerce extends boolean = false > extends ZodType <
1821
1826
Date ,
1822
- ZodDateDef ,
1827
+ ZodDateDef < TCoerce > ,
1823
1828
TCoerce extends true ? unknown : Date
1824
1829
> {
1825
1830
_parse ( input : ParseInput ) : ParseReturnType < this[ "_output" ] > {
@@ -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