Skip to content

Instantly share code, notes, and snippets.

@jswhisperer
Last active June 6, 2025 19:44
Show Gist options
  • Save jswhisperer/efcefb27270fecd0f506ac8742d4eeeb to your computer and use it in GitHub Desktop.
Save jswhisperer/efcefb27270fecd0f506ac8742d4eeeb to your computer and use it in GitHub Desktop.
do await typed
const doAwait = async <T>(promise: Promise<T>): Promise<[undefined, T] | [Error, undefined]> => {
try {
const data = await promise;
return [undefined, data];
} catch (error) {
return [error as Error, undefined];
}
};
const [error, result] = await doAwait(myPromise);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment