evl
Version:
Function fallback when error.
18 lines (17 loc) • 900 B
TypeScript
/**
* Call the main function and return value when successfully call.
* Otherwise, call and return value from the fallback function (or value).
*
* (`null` will be return when both functions are unsuccessfully called.)
*
* @exports
* @template A1 Arguments of the main function
* @template A2 Arguments of the fallback function
* @template R1 Value of the main function
* @template R2 Value of the fallback function
* @param {(((...args1: A1) => R1) | R1)} mainFunction Main function or value
* @param {(((...args2: A2) => R2) | R2)} fallbackFunction Fallback function or value
* @returns A function that return value from either of given functions
*/
declare function evl<A1 extends any[], A2 extends any[], R1, R2>(mainFunction: ((...args1: A1) => R1) | R1, fallbackFunction: ((...args2: A2) => R2) | R2): (mainArgs?: A1, fallbackArgs?: A2) => R1 | R2;
export = evl;