@monstermann/fn
Version:
A utility library for TypeScript.
23 lines • 658 B
TypeScript
//#region src/promise/orElse.d.ts
/**
* `orElse(target, onRejected)`
*
* Catches rejected promises and handles them with `onRejected`. This is an alias for `Promise.catch`.
*
* ```ts
* orElse(Promise.reject("error"), () => "fallback"); // Promise<"fallback">
* ```
*
* ```ts
* pipe(
* Promise.reject("error"),
* orElse(() => "fallback"),
* ); // Promise<"fallback">
* ```
*/
declare const orElse: {
<T, U>(onRejected: (reason: unknown) => U | PromiseLike<U>): (target: Promise<T>) => Promise<T | U>;
<T, U>(target: Promise<T>, onRejected: (reason: unknown) => U | PromiseLike<U>): Promise<T | U>;
};
//#endregion
export { orElse };