Last active
June 5, 2025 17:28
-
-
Save jswhisperer/8d8b319fe8b1b8f17c16f286b57ef60f to your computer and use it in GitHub Desktop.
typed try catch
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
| type TryCatchProps<T> = { | |
| tryFn: () => T; | |
| catchFn: (error: unknown) => T; | |
| } | |
| function tryCatch<T>({ tryFn, catchFn }: TryCatchProps<T>): T { | |
| try { | |
| return tryFn(); | |
| } catch (error) { | |
| return catchFn(error); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment