Last active
March 9, 2021 13:50
-
-
Save 9oelM/32479d991835abe36b76df719025bf49 to your computer and use it in GitHub Desktop.
Try catch sync wrapper
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 tcSync<Fn extends (...args: any) => any, Deps extends Parameters<Fn> = Parameters<Fn>>(fn: Fn, deps: Deps): TcResult<ReturnType<Fn>> { | |
try { | |
const data: ReturnType<Fn> = fn(...deps); | |
return [null, data]; | |
} catch (e) { | |
return [e] as [Error] | |
} | |
} | |
export type TcResult<Data> = [null, Data] | [Error]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment