@@ -3033,11 +3033,11 @@ export const omit = <A, I, Keys extends ReadonlyArray<keyof A & keyof I>>(...key
3033
3033
export const pluck : {
3034
3034
< A , I , K extends keyof A & keyof I > (
3035
3035
key : K
3036
- ) : < R > ( schema : Schema < A , I , R > ) => Schema < A [ K ] , Simplify < Pick < I , K > > , R >
3036
+ ) : < R > ( schema : Schema < A , I , R > ) => SchemaClass < A [ K ] , Simplify < Pick < I , K > > , R >
3037
3037
< A , I , R , K extends keyof A & keyof I > (
3038
3038
schema : Schema < A , I , R > ,
3039
3039
key : K
3040
- ) : Schema < A [ K ] , Simplify < Pick < I , K > > , R >
3040
+ ) : SchemaClass < A [ K ] , Simplify < Pick < I , K > > , R >
3041
3041
} = dual (
3042
3042
2 ,
3043
3043
< A , I , R , K extends keyof A & keyof I > (
@@ -3046,7 +3046,7 @@ export const pluck: {
3046
3046
) : Schema < A [ K ] , Pick < I , K > , R > => {
3047
3047
const ps = AST . getPropertyKeyIndexedAccess ( AST . typeAST ( schema . ast ) , key )
3048
3048
const value = make < A [ K ] , A [ K ] , R > ( ps . isOptional ? AST . orUndefined ( ps . type ) : ps . type )
3049
- return transform (
3049
+ const out = transform (
3050
3050
schema . pipe ( pick ( key ) ) ,
3051
3051
value ,
3052
3052
{
@@ -3055,6 +3055,7 @@ export const pluck: {
3055
3055
encode : ( ak ) => ps . isOptional && ak === undefined ? { } : { [ key ] : ak } as any
3056
3056
}
3057
3057
)
3058
+ return out
3058
3059
}
3059
3060
)
3060
3061
@@ -3900,7 +3901,11 @@ export const transform: {
3900
3901
* @category api interface
3901
3902
* @since 3.10.0
3902
3903
*/
3903
- export interface transformLiteral < Type , Encoded > extends Annotable < transformLiteral < Type , Encoded > , Type , Encoded > { }
3904
+ export interface transformLiteral < Type extends AST . LiteralValue , Encoded extends AST . LiteralValue >
3905
+ extends transform < Literal < [ Encoded ] > , Literal < [ Type ] > >
3906
+ {
3907
+ annotations ( annotations : Annotations . Schema < Type > ) : transformLiteral < Type , Encoded >
3908
+ }
3904
3909
3905
3910
/**
3906
3911
* Creates a new `Schema` which transforms literal values.
@@ -3917,11 +3922,12 @@ export interface transformLiteral<Type, Encoded> extends Annotable<transformLite
3917
3922
* @category constructors
3918
3923
* @since 3.10.0
3919
3924
*/
3920
- export const transformLiteral = < Encoded extends AST . LiteralValue , Type extends AST . LiteralValue > (
3925
+ export function transformLiteral < Encoded extends AST . LiteralValue , Type extends AST . LiteralValue > (
3921
3926
from : Encoded ,
3922
3927
to : Type
3923
- ) : transformLiteral < Type , Encoded > =>
3924
- transform ( Literal ( from ) , Literal ( to ) , { strict : true , decode : ( ) => to , encode : ( ) => from } )
3928
+ ) : transformLiteral < Type , Encoded > {
3929
+ return transform ( Literal ( from ) , Literal ( to ) , { strict : true , decode : ( ) => to , encode : ( ) => from } )
3930
+ }
3925
3931
3926
3932
/**
3927
3933
* Creates a new `Schema` which maps between corresponding literal values.
@@ -5159,14 +5165,16 @@ export const nonNegative = <S extends Schema.Any>(
5159
5165
* @category number transformations
5160
5166
* @since 3.10.0
5161
5167
*/
5162
- export const clamp =
5163
- ( minimum : number , maximum : number ) =>
5164
- < A extends number , I , R > ( self : Schema < A , I , R > ) : transform < Schema < A , I , R > , filter < Schema < A > > > =>
5165
- transform (
5166
- self ,
5167
- self . pipe ( typeSchema , between ( minimum , maximum ) ) ,
5168
- { strict : false , decode : ( self ) => number_ . clamp ( self , { minimum, maximum } ) , encode : identity }
5169
- )
5168
+ export const clamp = ( minimum : number , maximum : number ) =>
5169
+ < S extends Schema . Any , A extends number > (
5170
+ self : S & Schema < A , Schema . Encoded < S > , Schema . Context < S > >
5171
+ ) : transform < S , filter < SchemaClass < A > > > => {
5172
+ return transform (
5173
+ self ,
5174
+ typeSchema ( self ) . pipe ( between ( minimum , maximum ) ) ,
5175
+ { strict : false , decode : ( self ) => number_ . clamp ( self , { minimum, maximum } ) , encode : identity }
5176
+ )
5177
+ }
5170
5178
5171
5179
/**
5172
5180
* Transforms a `string` into a `number` by parsing the string using the `parse`
@@ -5542,14 +5550,15 @@ export const nonPositiveBigInt = <S extends Schema.Any>(
5542
5550
* @category bigint transformations
5543
5551
* @since 3.10.0
5544
5552
*/
5545
- export const clampBigInt =
5546
- ( minimum : bigint , maximum : bigint ) =>
5547
- < A extends bigint , I , R > ( self : Schema < A , I , R > ) : transform < Schema < A , I , R > , filter < Schema < A > > > =>
5548
- transform (
5549
- self ,
5550
- self . pipe ( typeSchema , betweenBigInt ( minimum , maximum ) ) ,
5551
- { strict : false , decode : ( self ) => bigInt_ . clamp ( self , { minimum, maximum } ) , encode : identity }
5552
- )
5553
+ export const clampBigInt = ( minimum : bigint , maximum : bigint ) =>
5554
+ < S extends Schema . Any , A extends bigint > (
5555
+ self : S & Schema < A , Schema . Encoded < S > , Schema . Context < S > >
5556
+ ) : transform < S , filter < SchemaClass < A > > > =>
5557
+ transform (
5558
+ self ,
5559
+ self . pipe ( typeSchema , betweenBigInt ( minimum , maximum ) ) ,
5560
+ { strict : false , decode : ( self ) => bigInt_ . clamp ( self , { minimum, maximum } ) , encode : identity }
5561
+ )
5553
5562
5554
5563
/** @ignore */
5555
5564
class BigInt$ extends transformOrFail (
@@ -5908,7 +5917,9 @@ export class Duration extends transform(
5908
5917
*/
5909
5918
export const clampDuration =
5910
5919
( minimum : duration_ . DurationInput , maximum : duration_ . DurationInput ) =>
5911
- < A extends duration_ . Duration , I , R > ( self : Schema < A , I , R > ) : transform < Schema < A , I , R > , filter < Schema < A > > > =>
5920
+ < S extends Schema . Any , A extends duration_ . Duration > (
5921
+ self : S & Schema < A , Schema . Encoded < S > , Schema . Context < S > >
5922
+ ) : transform < S , filter < SchemaClass < A > > > =>
5912
5923
transform (
5913
5924
self ,
5914
5925
self . pipe ( typeSchema , betweenDuration ( minimum , maximum ) ) ,
@@ -6377,29 +6388,39 @@ export const getNumberIndexedAccess = <A extends ReadonlyArray<any>, I extends R
6377
6388
* @category ReadonlyArray transformations
6378
6389
* @since 3.10.0
6379
6390
*/
6380
- export const head = < A , I , R > (
6381
- self : Schema < ReadonlyArray < A > , I , R >
6382
- ) : transform < Schema < ReadonlyArray < A > , I , R > , OptionFromSelf < SchemaClass < A > > > =>
6383
- transform (
6391
+ export function head < S extends Schema . Any , A extends ReadonlyArray < unknown > > (
6392
+ self : S & Schema < A , Schema . Encoded < S > , Schema . Context < S > >
6393
+ ) : transform < S , OptionFromSelf < SchemaClass < A [ number ] > > > {
6394
+ return transform (
6384
6395
self ,
6385
6396
OptionFromSelf ( getNumberIndexedAccess ( typeSchema ( self ) ) ) ,
6386
- { strict : true , decode : array_ . head , encode : option_ . match ( { onNone : ( ) => [ ] , onSome : array_ . of } ) }
6397
+ {
6398
+ strict : false ,
6399
+ decode : array_ . head ,
6400
+ encode : option_ . match ( { onNone : ( ) => [ ] , onSome : array_ . of } )
6401
+ }
6387
6402
)
6403
+ }
6388
6404
6389
6405
/**
6390
6406
* Get the first element of a `NonEmptyReadonlyArray`.
6391
6407
*
6392
6408
* @category NonEmptyReadonlyArray transformations
6393
6409
* @since 3.12.0
6394
6410
*/
6395
- export const headNonEmpty = < A , I , R > (
6396
- self : Schema < array_ . NonEmptyReadonlyArray < A > , I , R >
6397
- ) : transform < Schema < readonly [ A , ... Array < A > ] , I , R > , SchemaClass < A > > =>
6398
- transform (
6411
+ export function headNonEmpty < S extends Schema . Any , A extends array_ . NonEmptyReadonlyArray < unknown > > (
6412
+ self : S & Schema < A , Schema . Encoded < S > , Schema . Context < S > >
6413
+ ) : transform < S , SchemaClass < A [ number ] > > {
6414
+ return transform (
6399
6415
self ,
6400
6416
getNumberIndexedAccess ( typeSchema ( self ) ) ,
6401
- { strict : true , decode : array_ . headNonEmpty , encode : array_ . of }
6417
+ {
6418
+ strict : false ,
6419
+ decode : array_ . headNonEmpty ,
6420
+ encode : ( x : A [ number ] ) => array_ . of ( x )
6421
+ }
6402
6422
)
6423
+ }
6403
6424
6404
6425
/**
6405
6426
* Retrieves the first element of a `ReadonlyArray`.
@@ -6410,13 +6431,15 @@ export const headNonEmpty = <A, I, R>(
6410
6431
* @since 3.10.0
6411
6432
*/
6412
6433
export const headOrElse : {
6413
- < A > (
6414
- fallback ?: LazyArg < A >
6415
- ) : < I , R > ( self : Schema < ReadonlyArray < A > , I , R > ) => transform < Schema < ReadonlyArray < A > , I , R > , SchemaClass < A > >
6416
- < A , I , R > (
6417
- self : Schema < ReadonlyArray < A > , I , R > ,
6418
- fallback ?: LazyArg < A >
6419
- ) : transform < Schema < ReadonlyArray < A > , I , R > , SchemaClass < A > >
6434
+ < S extends Schema . Any , A extends ReadonlyArray < unknown > > (
6435
+ fallback ?: LazyArg < A [ number ] >
6436
+ ) : (
6437
+ self : S & Schema < A , Schema . Encoded < S > , Schema . Context < S > >
6438
+ ) => transform < S , SchemaClass < A [ number ] > >
6439
+ < S extends Schema . Any , A extends ReadonlyArray < unknown > > (
6440
+ self : S & Schema < A , Schema . Encoded < S > , Schema . Context < S > > ,
6441
+ fallback ?: LazyArg < A [ number ] >
6442
+ ) : transform < S , SchemaClass < A [ number ] > >
6420
6443
} = dual (
6421
6444
( args ) => isSchema ( args [ 0 ] ) ,
6422
6445
< A , I , R > (
@@ -7535,7 +7558,7 @@ export {
7535
7558
export const ReadonlyMapFromRecord = < KA , KR , VA , VI , VR > ( { key, value } : {
7536
7559
key : Schema < KA , string , KR >
7537
7560
value : Schema < VA , VI , VR >
7538
- } ) : Schema < ReadonlyMap < KA , VA > , { readonly [ x : string ] : VI } , KR | VR > =>
7561
+ } ) : SchemaClass < ReadonlyMap < KA , VA > , { readonly [ x : string ] : VI } , KR | VR > =>
7539
7562
transform (
7540
7563
Record ( { key : encodedBoundSchema ( key ) , value } ) . annotations ( {
7541
7564
description : "a record to be decoded into a ReadonlyMap"
@@ -7555,7 +7578,7 @@ export const ReadonlyMapFromRecord = <KA, KR, VA, VI, VR>({ key, value }: {
7555
7578
export const MapFromRecord = < KA , KR , VA , VI , VR > ( { key, value } : {
7556
7579
key : Schema < KA , string , KR >
7557
7580
value : Schema < VA , VI , VR >
7558
- } ) : Schema < Map < KA , VA > , { readonly [ x : string ] : VI } , KR | VR > =>
7581
+ } ) : SchemaClass < Map < KA , VA > , { readonly [ x : string ] : VI } , KR | VR > =>
7559
7582
transform (
7560
7583
Record ( { key : encodedBoundSchema ( key ) , value } ) . annotations ( {
7561
7584
description : "a record to be decoded into a Map"
@@ -8021,7 +8044,9 @@ export const betweenBigDecimal = <S extends Schema.Any>(
8021
8044
*/
8022
8045
export const clampBigDecimal =
8023
8046
( minimum : bigDecimal_ . BigDecimal , maximum : bigDecimal_ . BigDecimal ) =>
8024
- < A extends bigDecimal_ . BigDecimal , I , R > ( self : Schema < A , I , R > ) : transform < Schema < A , I , R > , filter < Schema < A > > > =>
8047
+ < S extends Schema . Any , A extends bigDecimal_ . BigDecimal > (
8048
+ self : S & Schema < A , Schema . Encoded < S > , Schema . Context < S > >
8049
+ ) : transform < S , filter < SchemaClass < A > > > =>
8025
8050
transform (
8026
8051
self ,
8027
8052
self . pipe ( typeSchema , betweenBigDecimal ( minimum , maximum ) ) ,
0 commit comments