Skip to content

Instantly share code, notes, and snippets.

@brettinternet
Last active December 15, 2022 22:57
Show Gist options
  • Save brettinternet/a823db203b074fd3f20a1e44cb5c538e to your computer and use it in GitHub Desktop.
Save brettinternet/a823db203b074fd3f20a1e44cb5c538e to your computer and use it in GitHub Desktop.
try catch hell 🤷‍♂️
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