• Wraps fn in a try...catch and returns the result of fn(x), or returns the fallback if fn(x) throws an error.

    Type Parameters

    • F extends ((...args) => any)

    Parameters

    • fn: F

    Returns ((fallback) => ((...args) => ReturnType<F>))

      • (fallback): ((...args) => ReturnType<F>)
      • Parameters

        • fallback: ReturnType<F>

        Returns ((...args) => ReturnType<F>)

          • (...args): ReturnType<F>
          • Parameters

            • Rest ...args: Parameters<F>

            Returns ReturnType<F>

    Example

    throwable(JSON.parse)('fallback')('["Good","JSON"]')
    // => ['Good', 'JSON']

    throwable(JSON.parse)('fallback')('[Bad, JSON]')
    // => 'fallback'

Generated using TypeDoc