result-guard
Version:
Type-safe error handling with discriminated unions and type guards for TypeScript
19 lines (17 loc) • 647 B
TypeScript
import { Result } from './types';
/**
* Handles a promise-returning function, ensuring all errors are caught
* and converted to the appropriate Result type.
*
* @param promise The promise to handle
* @returns A promise that resolves to a Result
*/
export declare function handlePromise<T, E = Error>(promise: Promise<T>): Promise<Result<T, E>>;
/**
* Safely resolves a promise, ensuring it's properly wrapped in Promise.resolve
* to handle both Promise-like objects and regular values.
*
* @param value The value to resolve
* @returns A proper Promise
*/
export declare function safeResolve<T>(value: T | PromiseLike<T>): Promise<T>;