export type TGetLatestAsyncFnOptions = { signal?: AbortSignal | null; }; export type TLatestAsyncFn = ((...args: TArgs) => Promise>) & { cancel: (reason?: unknown) => void; pending: () => boolean; }; export type TLatestAsyncSource = (signal: AbortSignal, ...args: TArgs) => TResult; export type TGetLatestAsyncFnArgs = Parameters; export type TGetLatestAsyncFnReturn = ReturnType; /** * Wraps an async operation so a new call aborts the previous pending call. * The source function receives a per-call signal as its first argument. * @template TArgs,TResult * @param {TLatestAsyncSource} fn Async source function * @param {TGetLatestAsyncFnOptions} [options={}] Shared lifecycle signal * @returns {TLatestAsyncFn} Latest-only async function with cancel controls * @throws {TypeError} getLatestAsyncFn: arguments are invalid * @example * const search = getLatestAsyncFn(async (signal, query: string) => { * const response = await fetch(`/api/search?q=${encodeURIComponent(query)}`, { signal }); * return response.json(); * }); * await search("roses"); * @example * // Abort the active request when a component is disposed * const lifecycle = new AbortController(); * const load = getLatestAsyncFn(loadProduct, { signal: lifecycle.signal }); * lifecycle.abort(); */ export declare const getLatestAsyncFn: (fn: TLatestAsyncSource, options?: TGetLatestAsyncFnOptions) => TLatestAsyncFn;