Skip to content

Commit

Permalink
fix(types): fix errors after new version of typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
hrajchert committed May 18, 2018
1 parent c1b421b commit b7d873f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { catchError, chain, IMapFn, IPipeFn, ITaskChainFn, map } from './operato


export class UncaughtError extends Error {
type: 'UncaughtError';
type: 'UncaughtError' = 'UncaughtError';

constructor (private error: any) {
super('UncaughtError: ' + error.toString());
Expand Down
10 changes: 7 additions & 3 deletions src/utils/case-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import { Task } from '../task';
export type Constructor<T> = { new(...args: any[]): T; };

export type IErrorHandler<E, TResult, EResult> = (err: E) => Task<TResult, EResult>;

export function caseError <E, TResult, EResult> (errorType: Constructor<E>, errorHandler: IErrorHandler<E, TResult, EResult>) {
return function <RE> (err: RE | E): Task<TResult, RE | EResult> {
// If the error is of the type we are looking for (E)
if (err instanceof errorType) {
return errorHandler(err);
// Transform the error
return errorHandler(err as E);
} else {
return Task.reject(err);
// If not, leave as it is
return Task.reject(err as RE);
}
};
}
}

0 comments on commit b7d873f

Please sign in to comment.