@@ -38,9 +38,6 @@ export class Task<E, S> implements PromiseLike<S> {
38
38
39
39
public fork : Fork < E , S > ;
40
40
41
- // eslint-disable-next-line @typescript-eslint/unbound-method
42
- public andThen = this . chain ;
43
-
44
41
constructor ( computation : Fork < E , S > ) {
45
42
this . fork = computation ;
46
43
}
@@ -78,8 +75,8 @@ export class Task<E, S> implements PromiseLike<S> {
78
75
return toPromise ( this ) ;
79
76
}
80
77
81
- public swap ( ) : Task < S , E > {
82
- return swap ( this ) ;
78
+ public swap < E2 extends E , S2 extends S > ( ) : Task < S2 , E2 > {
79
+ return swap < E , S , E2 , S2 > ( this ) ;
83
80
}
84
81
85
82
public map < S2 > ( fn : ( result : S ) => S2 ) : Task < E , S2 > {
@@ -300,7 +297,6 @@ export function fork<E, S>(
300
297
301
298
/**
302
299
* Chain a task to run after a previous task has succeeded.
303
- * @alias andThen
304
300
* @param fn Takes a successful result and returns a new task.
305
301
* @param task The task which will chain to the next one on success.
306
302
*/
@@ -313,8 +309,6 @@ export function chain<E, S, S2>(
313
309
) ;
314
310
}
315
311
316
- export const andThen = chain ;
317
-
318
312
/**
319
313
* If a function returns a Promise instead of a Task, automatically
320
314
* convert it to a Task.
@@ -700,8 +694,15 @@ export function sequence<E, S>(
700
694
* Given a task, swap the error and success values.
701
695
* @param task The task to swap the results of.
702
696
*/
703
- export function swap < E , S > ( task : Task < E , S > ) : Task < S , E > {
704
- return new Task < S , E > ( ( reject , resolve ) => task . fork ( resolve , reject ) ) ;
697
+ export function swap < E , S , E2 extends E , S2 extends S > (
698
+ task : Task < E , S >
699
+ ) : Task < S2 , E2 > {
700
+ return new Task < S2 , E2 > ( ( reject , resolve ) =>
701
+ task . fork (
702
+ e => resolve ( e as E2 ) ,
703
+ s => reject ( s as S2 )
704
+ )
705
+ ) ;
705
706
}
706
707
707
708
/**
0 commit comments