[Refactoring] Better typings for safeExec

This commit is contained in:
Alexander Zinchuk 2024-09-19 20:43:49 +02:00
parent 22019bc86c
commit be4c220228

View File

@ -3,7 +3,11 @@ import { handleError } from './handleError';
const SAFE_EXEC_ENABLED = !DEBUG_MORE;
export default function safeExec(cb: Function, rescue?: (err: Error) => void, always?: NoneToVoidFunction) {
export default function safeExec<F extends AnyFunction>(
cb: F,
rescue?: (err: Error) => void,
always?: NoneToVoidFunction,
): ReturnType<F> | undefined {
if (!SAFE_EXEC_ENABLED) {
return cb();
}