Files
SnowLuma/.pnpm-store/v11/files/fc/228248f95914717a6a9e61977e7a7324235b3dafe06a79bf2bdeda67a9f5ddf0eb468354b3dfe4e8a701d12e2065576bab49587b3486d71d02693e9729dfb4
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

38 lines
1.3 KiB
Plaintext

import { defaultSerializeError } from './router.cjs';
/**
* Well-known symbol used by {@link defer} to tag a promise with
* its deferred state. Consumers can read `promise[TSR_DEFERRED_PROMISE]`
* to access `status`, `data`, or `error`.
*/
export declare const TSR_DEFERRED_PROMISE: unique symbol;
export type DeferredPromiseState<T> = {
status: 'pending';
data?: T;
error?: unknown;
} | {
status: 'success';
data: T;
} | {
status: 'error';
data?: T;
error: unknown;
};
export type DeferredPromise<T> = Promise<T> & {
[TSR_DEFERRED_PROMISE]: DeferredPromiseState<T>;
};
/**
* Wrap a promise with a deferred state for use with `<Await>` and `useAwaited`.
*
* The returned promise is augmented with internal state (status/data/error)
* so UI can read progress or suspend until it settles.
*
* @param _promise The promise to wrap.
* @param options Optional config. Provide `serializeError` to customize how
* errors are serialized for transfer.
* @returns The same promise with attached deferred metadata.
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/deferFunction
*/
export declare function defer<T>(_promise: Promise<T>, options?: {
serializeError?: typeof defaultSerializeError;
}): DeferredPromise<T>;