Last active
December 15, 2022 22:57
-
-
Save brettinternet/a823db203b074fd3f20a1e44cb5c538e to your computer and use it in GitHub Desktop.
try catch hell 🤷♂️
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
const tc = | |
<T extends (...args: Parameters<T>) => ReturnType<T>>( | |
cb: T, | |
condition = true | |
): ((...args: Parameters<T>) => ReturnType<T> | undefined) => | |
(...args: Parameters<T>) => { | |
if (condition) { | |
try { | |
return cb(...args) | |
} catch (error) { | |
console.error(error) | |
} | |
} | |
return | |
} | |
tc(setup, 'key' in config)?.(arg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment