Skip to content

Type Alias: CancellablePromise<T> ​

CancellablePromise<T> = Promise<T> & object

Defined in: src/types/instance.ts:24

A Promise<T> with an attached .cancel() method that aborts the in-flight request.

Cancelling rejects the promise with a ValifetchError whose code is 'ABORT_ERROR'.

Type Parameters ​

T ​

T

Type Declaration ​

cancel() ​

cancel(): void

Aborts the in-flight request. The promise rejects with a ValifetchError whose code is 'ABORT_ERROR'.

Returns ​

void

Example ​

ts
const req = api.get('/slow-endpoint');
req.cancel(); // aborts immediately
try {
  await req;
} catch (err) {
  // err.code === 'ABORT_ERROR'
}

Released under the MIT License. Built with Claude Code.