-
-
Save dlo/012fb10ce27e8426c633bb70f106009e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Typescript erroring: | |
--- | |
Type 'Promise<(T | undefined)[] | [any, undefined]>' is not assignable to type 'Promise<[void | Error, void | T]>'. | |
Type '(T | undefined)[] | [any, undefined]' is not assignable to type '[void | Error, void | T]'. | |
Type '(T | undefined)[]' is not assignable to type '[void | Error, void | T]'. | |
Target requires 2 element(s) but source may have fewer.ts(2322) | |
*/ | |
export default function <T> (promise: Promise<T>): Promise<[Error | void, T | void]> { | |
return promise | |
.then((data) => ([undefined, data])) | |
.catch((error) => ([error, undefined])) | |
} | |
/* | |
Usage: | |
const [err, res] = await handle(Axios.get('/api/foo')) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment