Function wrapFunctionWithOptionalArgs

  • Wraps a function to handle optional arguments as an array.

    Type Parameters

    • T extends unknown[]

      The tuple type of the required arguments.

    • U

      The type of the optional arguments.

    Parameters

    • fn: ((...args) => void)

      The function to wrap.

        • (...args): void
        • Parameters

          • Rest ...args: [...T[], U[]]

          Returns void

    Returns ((...args) => void)

    • The wrapped function.
      • (...args): void
      • Parameters

        • Rest ...args: [...T[], ...U[]]

        Returns void

    Example

    const wrappedFn = wrapFunctionWithOptionalArgs((a: number, b: number, options: number[]) => {
    console.log(a, b, options);
    });
    wrappedFn(1, 2, 3, 4, 5); // Output: 1 2 [3, 4, 5]

Generated using TypeDoc