@ruingl/pcall
Version:
Calls your functions protected from errors.
29 lines (26 loc) • 920 B
text/typescript
/**
* Result of a protected call.
*/
type Result<T> = {
/** Status if it succeeded or failed. */
status: boolean;
/** Result of the call if it suceeded. */
result?: T;
/** Error of the call if it failed. */
error?: Error;
};
/**
* Calls a function protected from errors. (Async)
* @param fn - Function to call.
* @param args - Arguments of function to call.
* @returns Result of the function called.
*/
declare function pcall<T extends (...args: unknown[]) => unknown>(fn: T, ...args: Parameters<T>): Promise<Result<Awaited<ReturnType<T>>>>;
/**
* Calls a function protected from errors. (Sync)
* @param fn - Function to call.
* @param args - Arguments of function to call.
* @returns Result of function called.
*/
declare function pcallSync<T extends (...args: unknown[]) => unknown>(fn: T, ...args: Parameters<T>): Result<ReturnType<T>>;
export { type Result, pcall, pcallSync };