From 384b7e6994c7392e4a39056ee5bb56755bcac11a Mon Sep 17 00:00:00 2001 From: Dmitriy Mozgovoy Date: Wed, 4 May 2022 22:23:01 +0300 Subject: [PATCH] Added generic `AxiosAbortSignal` TS interface to avoid importing AbortController 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 --- index.d.ts | 9 ++++++++- test/typescript/axios.ts | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 54610e3c4b..94b076cb13 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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 { url?: string; method?: Method | string; @@ -105,7 +112,7 @@ export interface AxiosRequestConfig { cancelToken?: CancelToken; decompress?: boolean; transitional?: TransitionalOptions; - signal?: AbortSignal; + signal?: GenericAbortSignal; insecureHTTPParser?: boolean; env?: { FormData?: new (...args: any[]) => object; diff --git a/test/typescript/axios.ts b/test/typescript/axios.ts index aa8c80dd0d..7c304de80c 100644 --- a/test/typescript/axios.ts +++ b/test/typescript/axios.ts @@ -375,3 +375,7 @@ axios.get('/user') // FormData axios.toFormData({x: 1}, new FormData()); + +// AbortSignal + +axios.get('/user', {signal: new AbortController().signal});