import { Constructor } from 'type-fest'; interface Success { ok: true; result: T; } interface Err { ok: false; result: E; } type Result = Success | Err; /** * Converts a Promise into a Result object. * Usefull for handling "expected" errors. If the error is not of the expected type, it will still be thrown ("unexpected" error). * Error type is cheked at runtime, so we have a guarantee that the error is of the expected type. No typescript cast wizardry here. * * @example * const result = await to(getUserData("123"), Error); * * if (result.ok) { * console.log("User data:", result.result); * } else { * console.error("Error:", result.result); * } */ declare function to(promise: Promise | (() => Promise), error: Constructor): Promise>; export { Success, Err, Result, to as default };