import { Func } from '../typings/types'; interface TryCatch { (tryer: Func, catcher: Func): Func; } /** * Takes two functions, tryer and catcher. * * Returns a function that, when invoked with zero or more parameters, * calls the tryer with those parameters, and if tryer throws, * calls the catcher with the error as first argument and original arguments as rest. * If that still throws, then ¯\_(ツ)_/¯ * * @param {Function} tryer * @param {Function} catcher * @return {Function} * @example * tryCatch(x => x.length, () => 0)([ 1, 2, 3 ]) // 3 * tryCatch(x => x.length, () => 0)( undefined ) // 0 * tryCatch( * someDataTransform, * (err, ...rest) => { * logAsyncToServer('someDataTransform failed', err, 'with arguments', rest); * return DEFAULT_VALUE; * } * )( someIncompleteData ) // DEFAULT_VALUE (error is logged somewhere) */ declare const _default: TryCatch; export default _default;