Skip to content

Instantly share code, notes, and snippets.

@NikolaRHristov
Last active September 7, 2023 22:06
Show Gist options
  • Save NikolaRHristov/c27afa3f18d93f6be34bf99cf5fa988c to your computer and use it in GitHub Desktop.
Save NikolaRHristov/c27afa3f18d93f6be34bf99cf5fa988c to your computer and use it in GitHub Desktop.
Checks if function returns void. Basically Wrap()
// rome-ignore lint/suspicious/noExplicitAny:
export default <T extends (...args: any[]) => any>(
Fn: T,
With?: Parameters<T>[0]
): ReturnType<T> | boolean => {
try {
const Return = typeof With !== "undefined" ? Fn(With) : Fn();
if (typeof Return !== "undefined") {
return Return;
}
} catch (_Error) {
console.log(_Error);
return false;
}
return true;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment