@@ -13,6 +13,20 @@ export interface DecoderError {
13
13
message : string ;
14
14
}
15
15
16
+ /**
17
+ * Alias for the result of the `Decoder.run` method. On success returns `Ok`
18
+ * with the decoded value of type `A`, on failure returns `Err` containing a
19
+ * `DecoderError`.
20
+ */
21
+ type RunResult < A > = Result . Result < A , DecoderError > ;
22
+
23
+ /**
24
+ * Alias for the result of the internal `Decoder.decode` method. Since `decode`
25
+ * is a private function it returns a partial decoder error on failure, which
26
+ * will be completed and polished when handed off to the `run` method.
27
+ */
28
+ type DecodeResult < A > = Result . Result < A , Partial < DecoderError > > ;
29
+
16
30
/**
17
31
* Defines a mapped type over an interface `A`. `DecoderObject<A>` is an
18
32
* interface that has all the keys or `A`, but each key's property type is
@@ -120,7 +134,7 @@ export class Decoder<A> {
120
134
* `andThen` and `map` should be enough to build specialized decoders as
121
135
* needed.
122
136
*/
123
- private constructor ( private decode : ( json : any ) => Result . Result < A , Partial < DecoderError > > ) { }
137
+ private constructor ( private decode : ( json : any ) => DecodeResult < A > ) { }
124
138
125
139
/**
126
140
* Decoder primitive that validates strings, and fails on all other input.
@@ -311,12 +325,12 @@ export class Decoder<A> {
311
325
*/
312
326
static array = < A > ( decoder : Decoder < A > ) : Decoder < A [ ] > =>
313
327
new Decoder < A [ ] > ( json => {
314
- const decodeValue = ( v : any , i : number ) : Result . Result < A , Partial < DecoderError > > =>
328
+ const decodeValue = ( v : any , i : number ) : DecodeResult < A > =>
315
329
Result . mapError ( err => prependAt ( `[${ i } ]` , err ) , decoder . decode ( v ) ) ;
316
330
317
331
return isJsonArray ( json )
318
332
? json . reduce (
319
- ( acc : Result . Result < A [ ] , Partial < DecoderError > > , v : any , i : number ) =>
333
+ ( acc : DecodeResult < A [ ] > , v : any , i : number ) =>
320
334
Result . map2 ( ( arr , result ) => [ ...arr , result ] , acc , decodeValue ( v , i ) ) ,
321
335
Result . ok ( [ ] )
322
336
)
@@ -602,7 +616,7 @@ export class Decoder<A> {
602
616
* // }
603
617
* ```
604
618
*/
605
- run = ( json : any ) : Result . Result < A , DecoderError > =>
619
+ run = ( json : any ) : RunResult < A > =>
606
620
Result . mapError (
607
621
error => ( {
608
622
kind : 'DecoderError' as 'DecoderError' ,
0 commit comments