Skip to content

Commit

Permalink
fix: chain should expand error types
Browse files Browse the repository at this point in the history
  • Loading branch information
tdreyno committed Mar 5, 2020
1 parent 13d9c5a commit 1525053
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion docs/task-instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ const task: Task<unknown, number> = Task.of(5).chain(number =>
{% tab title="Type Definition" %}

```typescript
type chain = <S2>(fn: (result: S) => Task<E, S2> | Promise<S2>) => Task<E, S2>
type chain = <S2>(
fn: (result: S) => Task<E2, S2> | Promise<S2>
) => Task<E | E2, S2>
```
{% endtab %}
Expand Down
6 changes: 3 additions & 3 deletions src/Task/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ export const fork = <E, S>(
* @param fn Takes a successful result and returns a new task.
* @param task The task which will chain to the next one on success.
*/
export const chain = <E, S, S2>(
fn: (result: S) => Task<E, S2> | Promise<S2>,
export const chain = <E, S, E2, S2>(
fn: (result: S) => Task<E2, S2> | Promise<S2>,
task: Task<E, S>
): Task<E, S2> =>
): Task<E | E2, S2> =>
new Task((reject, resolve) =>
task.fork(reject, b => autoPromiseToTask(fn(b)).fork(reject, resolve))
)
Expand Down

0 comments on commit 1525053

Please sign in to comment.