Skip to content

Commit

Permalink
Fixed typing for non-promises & added err typing
Browse files Browse the repository at this point in the history
Function works with thenable non-promises and returns an Error or a custom error type
  • Loading branch information
ciriousjoker authored Jun 26, 2018
1 parent c7464d0 commit f6a1159
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/await-to-js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
* @param { Object= } errorExt - Additional Information you can pass to the err object
* @return { Promise }
*/
export function to<T, U = any>(
promise: Promise<T>,
export function to<T, U = Error>(
promise: any,
errorExt?: object
): Promise<[U | null, T | undefined]> {
return promise
.then<[null, T]>((data: T) => [null, data])
.catch<[U, undefined]>(err => {
.then((data: T) => [null, data])
.catch((err: U) => {
if (errorExt) {
Object.assign(err, errorExt)
}
Expand Down

0 comments on commit f6a1159

Please sign in to comment.