Last active
September 15, 2021 19:54
-
-
Save fed135/d4d1e6b1d1f384aedfcb86dc0da05736 to your computer and use it in GitHub Desktop.
Functional await spread
This file contains 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
export function to<T = any>(promise: Promise<T>): Promise<[null, T] | [any, null?]> { | |
return promise | |
.then((data) => [null, data] as [null, T]) | |
.catch((err) => [err] as [any]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment