Last active
June 6, 2025 19:44
-
-
Save jswhisperer/efcefb27270fecd0f506ac8742d4eeeb to your computer and use it in GitHub Desktop.
do await typed
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
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]; | |
} | |
}; |
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
const [error, result] = await doAwait(myPromise); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment