Skip to content

Commit

Permalink
Added generic AxiosAbortSignal TS interface to avoid importing Abor…
Browse files Browse the repository at this point in the history
…tController polyfill (#4229)

* Added generic `AxiosAbortSignal` TS interface to avoid importing AbortController polyfill;

* Renamed `AxiosAbortSignal` to `GenericAbortSignal` to use the same naming style as `GenericFormData`;

* Added TS test for `GenericAbortSignal` interface;

Co-authored-by: Jay <jasonsaayman@gmail.com>
  • Loading branch information
DigitalBrainJS and jasonsaayman committed May 4, 2022
1 parent eaaab30 commit 384b7e6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion index.d.ts
Expand Up @@ -72,6 +72,13 @@ export interface TransitionalOptions {
clarifyTimeoutError?: boolean;
}

export interface GenericAbortSignal {
aborted: boolean;
onabort: ((...args: any) => any) | null;
addEventListener: (...args: any) => any;
removeEventListener: (...args: any) => any;
}

export interface AxiosRequestConfig<D = any> {
url?: string;
method?: Method | string;
Expand Down Expand Up @@ -105,7 +112,7 @@ export interface AxiosRequestConfig<D = any> {
cancelToken?: CancelToken;
decompress?: boolean;
transitional?: TransitionalOptions;
signal?: AbortSignal;
signal?: GenericAbortSignal;
insecureHTTPParser?: boolean;
env?: {
FormData?: new (...args: any[]) => object;
Expand Down
4 changes: 4 additions & 0 deletions test/typescript/axios.ts
Expand Up @@ -375,3 +375,7 @@ axios.get('/user')
// FormData

axios.toFormData({x: 1}, new FormData());

// AbortSignal

axios.get('/user', {signal: new AbortController().signal});

0 comments on commit 384b7e6

Please sign in to comment.