@naturalcycles/js-lib
Version:
Standard library for universal (browser + Node.js) javascript
32 lines (31 loc) • 905 B
TypeScript
import type { CommonLogger } from '../log/commonLogger.js';
import type { AnyFunction } from '../types.js';
export interface TryCatchOptions {
/**
* The value returned from the function will be returned from the wrapped method (!).
* onError function may be asynchronous.
*/
onError?: (err: Error) => any;
/**
* @default false
*/
logSuccess?: boolean;
/**
* @default true
*/
logError?: boolean;
/**
* Default to `console`
*/
logger?: CommonLogger;
}
/**
* Decorates a function with "try/catch", so it'll never reject/throw.
* Only applies to async functions (or, turns sync function into async).
*
* Allows to pass onError callback.
*
* @experimental
*/
export declare function _tryCatch<T extends AnyFunction>(fn: T, opt?: TryCatchOptions): T;
export declare const _TryCatch: (opt?: TryCatchOptions) => MethodDecorator;