@@ -195,7 +195,12 @@ export function Array<ValueSchema extends S.Top>(value: ValueSchema) {
195195/**
196196 * An annotated `S.Array` of unique items that decodes to a `ReadonlySet`.
197197 */
198- export const ReadonlySetFromArray = < ValueSchema extends S . Top > ( value : ValueSchema ) => {
198+ export const ReadonlySetFromArray = < ValueSchema extends S . Top > ( value : ValueSchema ) : S . Codec <
199+ ReadonlySet < ValueSchema [ "Type" ] > ,
200+ readonly ValueSchema [ "Encoded" ] [ ] ,
201+ ValueSchema [ "DecodingServices" ] ,
202+ ValueSchema [ "EncodingServices" ]
203+ > => {
199204 const from = S
200205 . Array ( value )
201206 . annotate ( { expected : "an array of unique items that will be decoded as a ReadonlySet" } )
@@ -204,9 +209,9 @@ export const ReadonlySetFromArray = <ValueSchema extends S.Top>(value: ValueSche
204209 S . decodeTo (
205210 to ,
206211 SchemaTransformation . transform ( {
207- decode : ( arr : globalThis . Array < S . Schema . Type < ValueSchema > > ) => new Set < S . Schema . Type < ValueSchema > > ( arr ) ,
208- encode : ( set : Set < S . Schema . Type < ValueSchema > > ) => [ ...set ] as globalThis . Array < S . Schema . Type < ValueSchema > >
209- } ) as any
212+ decode : ( arr ) => new Set ( arr ) as ReadonlySet < S . Schema . Type < ValueSchema > > ,
213+ encode : ( set ) => [ ...set ]
214+ } )
210215 )
211216 )
212217 return S . revealCodec ( schema )
@@ -218,7 +223,12 @@ export const ReadonlySetFromArray = <ValueSchema extends S.Top>(value: ValueSche
218223export const ReadonlyMapFromArray = < KeySchema extends S . Top , ValueSchema extends S . Top > ( pair : {
219224 readonly key : KeySchema
220225 readonly value : ValueSchema
221- } ) => {
226+ } ) : S . Codec <
227+ ReadonlyMap < KeySchema [ "Type" ] , S . Schema . Type < ValueSchema > > ,
228+ readonly ( readonly [ KeySchema [ "Encoded" ] , ValueSchema [ "Encoded" ] ] ) [ ] ,
229+ KeySchema [ "DecodingServices" ] | ValueSchema [ "DecodingServices" ] ,
230+ KeySchema [ "EncodingServices" ] | ValueSchema [ "EncodingServices" ]
231+ > => {
222232 const from = S
223233 . Array ( S . Tuple ( [ pair . key , pair . value ] ) )
224234 . annotate ( { expected : "an array of key-value tuples that will be decoded as a ReadonlyMap" } )
@@ -230,15 +240,12 @@ export const ReadonlyMapFromArray = <KeySchema extends S.Top, ValueSchema extend
230240 to ,
231241 SchemaTransformation . transform ( {
232242 decode : (
233- arr : globalThis . Array < readonly [ S . Schema . Type < KeySchema > , S . Schema . Type < ValueSchema > ] >
234- ) => new Map < S . Schema . Type < KeySchema > , S . Schema . Type < ValueSchema > > ( arr ) ,
243+ arr
244+ ) => new Map ( arr ) as ReadonlyMap < S . Schema . Type < KeySchema > , S . Schema . Type < ValueSchema > > ,
235245 encode : (
236- map : Map < S . Schema . Type < KeySchema > , S . Schema . Type < ValueSchema > >
237- ) =>
238- [ ...map . entries ( ) ] as globalThis . Array <
239- readonly [ S . Schema . Type < KeySchema > , S . Schema . Type < ValueSchema > ]
240- >
241- } ) as any
246+ map
247+ ) => [ ...map . entries ( ) ] as any // fu
248+ } )
242249 )
243250 )
244251 return S . revealCodec ( schema )
0 commit comments