trysafely
Version:
A robust async helper to wrap promises and functions, returning [result, error] for graceful error handling.
18 lines • 921 B
TypeScript
import { Result } from "src";
/**
* A robust asynchronous helper designed to simplify error handling by wrapping
* an already-instantiated Promise. It consistently returns a `Result<T>` object
* (`{ result: T, error: null }` on success or `{ result: null, error: Error }` on failure),
* allowing consumers to destructure and handle errors explicitly.
*
* This function is concise for direct use with promises that are already created and
* potentially executing.
*
* @template T The expected type of the successful asynchronous result.
* @param {Promise<T>} promise The promise instance to execute and handle.
* @returns {Promise<Result<T>>} A Promise that resolves to a `Result<T>` object.
* - On success: `{ result: T, error: null }`
* - On failure: `{ result: null, error: Error }`
*/
export default function tryPromise<T>(promise: Promise<T>): Promise<Result<T>>;
//# sourceMappingURL=index.d.ts.map