Permalink
Switch branches/tags
Nothing to show
Find file Copy path
fc562a6 Oct 1, 2017
1 contributor

Users who have contributed to this file

22 lines (19 sloc) 490 Bytes
/**
* @param { Promise } promise
* @param { Object= } errorExt - Additional Information you can pass to the err object
* @return { Promise }
*/
export function to<T, U = any>(
promise: Promise<T>,
errorExt?: object
): Promise<[U | null, T | undefined]> {
return promise
.then<[null, T]>((data: T) => [null, data])
.catch<[U, undefined]>(err => {
if (errorExt) {
Object.assign(err, errorExt)
}
return [err, undefined]
})
}
export default to