From 89c40f3d95e53fef62c24e0ada7dc459dd297bc5 Mon Sep 17 00:00:00 2001 From: cprayer Date: Fri, 14 Aug 2020 22:59:52 +0900 Subject: [PATCH] Fixing an issue that type 'null' and 'undefined' is not assignable to validateStatus when typescript strict option is enabled --- index.d.ts | 2 +- test/typescript/axios.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 8a571eae6d..c860d8662c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -62,7 +62,7 @@ export interface AxiosRequestConfig { onUploadProgress?: (progressEvent: any) => void; onDownloadProgress?: (progressEvent: any) => void; maxContentLength?: number; - validateStatus?: ((status: number) => boolean | null); + validateStatus?: ((status: number) => boolean) | null; maxBodyLength?: number; maxRedirects?: number; socketPath?: string | null; diff --git a/test/typescript/axios.ts b/test/typescript/axios.ts index c584dfc578..c244cb1aa7 100644 --- a/test/typescript/axios.ts +++ b/test/typescript/axios.ts @@ -44,6 +44,14 @@ const config: AxiosRequestConfig = { cancelToken: new axios.CancelToken((cancel: Canceler) => {}) }; +const nullValidateStatusConfig: AxiosRequestConfig = { + validateStatus: null +}; + +const undefinedValidateStatusConfig: AxiosRequestConfig = { + validateStatus: undefined +}; + const handleResponse = (response: AxiosResponse) => { console.log(response.data); console.log(response.status);