//#region src/types.d.ts /** * The state of the promise. * @template TData The type of the return value. * @template TError The type of the error. */ type PromiseState = { data: null | TData | undefined; error: null | undefined; status: 'pending'; } | { data: null | TData | undefined; error: TError; status: 'error'; } | { data: null | undefined; error: null | undefined; status: 'idle'; } | { data: TData; error: null | undefined; status: 'success'; }; //#endregion //#region src/index.d.ts /** * A Vue composable for managing async operations with reactive state, * cancellation support, and race-condition safety. * * Designed for UI stability: * - Preserves previous data during reloads and errors * - Prevents stale responses from overwriting newer ones * - Supports request cancellation via AbortController * @template TData Resolved value type * @template TError Error type (must extend Error) * @template TArguments Argument tuple passed to the callback * @param callback Async function that receives an AbortSignal as its first argument * @returns The resolved value if successful, otherwise undefined. * @example * const { state, execute } = usePromise( * async (signal, id: string) => fetch(`/api/users/${id}`, { signal }).then(response => response.json()) * ) * * execute('123') */ declare function usePromise = []>(callback: (signal: AbortSignal, ...args: TArguments) => Promise): { /** Reactive promise state */ state: Readonly | null | undefined; readonly error: null | undefined; readonly status: "pending"; } | { readonly data: import("vue").DeepReadonly | null | undefined; readonly error: import("vue").DeepReadonly; readonly status: "error"; } | { readonly data: import("vue").DeepReadonly; readonly error: null | undefined; readonly status: "success"; }, { readonly data: null | undefined; readonly error: null | undefined; readonly status: "idle"; } | { readonly data: import("vue").DeepReadonly | null | undefined; readonly error: null | undefined; readonly status: "pending"; } | { readonly data: import("vue").DeepReadonly | null | undefined; readonly error: import("vue").DeepReadonly; readonly status: "error"; } | { readonly data: import("vue").DeepReadonly; readonly error: null | undefined; readonly status: "success"; }>>; /** Execute the async operation */ execute: (...args: TArguments) => Promise; /** Abort any in-flight request */ abort: () => void; /** Reset the promise state */ reset: () => void; }; //#endregion export { type PromiseState, usePromise };