---
url: https://haihv.github.io/valifetch/api/index/type-aliases/CancellablePromise.md
---

# Type Alias: CancellablePromise\<T>

> **CancellablePromise**<`T`> = `Promise`<`T`> & `object`

Defined in: [src/types/instance.ts:24](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/instance.ts#L24)

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'
}
```
