|
|
|
@@ -5,14 +5,10 @@ |
|
|
|
*/ |
|
|
|
|
|
|
|
/** |
|
|
|
* Safely invokes a function with a given value, returning the result of the |
|
|
|
* function or the provided value if it is `undefined` or `null`. |
|
|
|
* 安全调用函数,如果参数是 `undefined` 或 `null`,直接返回 `undefined` 或 `null`,而不会导致异常 |
|
|
|
* |
|
|
|
* @template T - The type of the input value. |
|
|
|
* @template M - The type of the output value. |
|
|
|
* @param {function} fn - The function to be invoked with the input value. |
|
|
|
* @returns {function} A function that takes a value, invokes `fn` with it if |
|
|
|
* it's not `undefined` or `null`, and returns the result or the original value. |
|
|
|
* @param fn - 要调用的函数 |
|
|
|
* @returns 封装后的函数,该函数的参数如果是 `undefined` 或 `null`,结果直接返回 `undefined` 或 `null`,而不会导致异常 |
|
|
|
*/ |
|
|
|
export function safeInvoke<T, M>( |
|
|
|
fn: (value: T) => M | undefined | null, |
|
|
|
|