Skip to content

Instantly share code, notes, and snippets.

@fed135
Last active September 15, 2021 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fed135/d4d1e6b1d1f384aedfcb86dc0da05736 to your computer and use it in GitHub Desktop.
Save fed135/d4d1e6b1d1f384aedfcb86dc0da05736 to your computer and use it in GitHub Desktop.
Functional await spread
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