From 9f992a8eb9ce67f589c3e9b56ae1d00279b3623a Mon Sep 17 00:00:00 2001 From: techcodie Date: Wed, 8 Apr 2026 00:28:30 +0530 Subject: [PATCH] fix(types): align runWhen type with runtime behavior in InterceptorManager (#7529) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `runWhen` property in `AxiosInterceptorOptions` and `AxiosInterceptorHandler` had type inconsistencies that caused TypeScript build failures when upgrading from axios 1.13.2 to 1.13.5+. Issues fixed: 1. `AxiosInterceptorOptions.runWhen` did not allow `null`, but `InterceptorManager.use()` explicitly sets it to `null` when no options are provided (`runWhen: options ? options.runWhen : null`). 2. `AxiosInterceptorHandler.runWhen` used `AxiosRequestConfig` instead of `InternalAxiosRequestConfig`, creating a type mismatch with `AxiosInterceptorOptions` which uses `InternalAxiosRequestConfig`. 3. In `index.d.ts`, the `AxiosInterceptorHandler.runWhen` type was `(config: AxiosRequestConfig) => boolean | null` — the `| null` was incorrectly placed as part of the return type rather than making the entire function type nullable. 4. `AxiosInterceptorHandler.runWhen` is now optional (`?`) to also allow `undefined`, matching the runtime case where options are passed without a `runWhen` property (i.e. `options.runWhen` is `undefined`). Fixes #7404 Co-authored-by: Jay --- index.d.cts | 4 ++-- index.d.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/index.d.cts b/index.d.cts index 918cb08f..c386ae82 100644 --- a/index.d.cts +++ b/index.d.cts @@ -629,7 +629,7 @@ declare namespace axios { interface AxiosInterceptorOptions { synchronous?: boolean; - runWhen?: (config: InternalAxiosRequestConfig) => boolean; + runWhen?: ((config: InternalAxiosRequestConfig) => boolean) | null; } type AxiosInterceptorFulfilled = (value: T) => T | Promise; @@ -650,7 +650,7 @@ declare namespace axios { fulfilled: AxiosInterceptorFulfilled; rejected?: AxiosInterceptorRejected; synchronous: boolean; - runWhen?: (config: AxiosRequestConfig) => boolean; + runWhen?: ((config: InternalAxiosRequestConfig) => boolean) | null; } interface AxiosInterceptorManager { diff --git a/index.d.ts b/index.d.ts index 300eb7c5..af25bd44 100644 --- a/index.d.ts +++ b/index.d.ts @@ -639,7 +639,7 @@ export interface CancelTokenSource { export interface AxiosInterceptorOptions { synchronous?: boolean; - runWhen?: (config: InternalAxiosRequestConfig) => boolean; + runWhen?: ((config: InternalAxiosRequestConfig) => boolean) | null; } type AxiosInterceptorFulfilled = (value: T) => T | Promise; @@ -660,7 +660,7 @@ interface AxiosInterceptorHandler { fulfilled: AxiosInterceptorFulfilled; rejected?: AxiosInterceptorRejected; synchronous: boolean; - runWhen: (config: AxiosRequestConfig) => boolean | null; + runWhen?: ((config: InternalAxiosRequestConfig) => boolean) | null; } export interface AxiosInterceptorManager {