mirror of
https://github.com/tenrok/axios.git
synced 2026-06-17 19:21:29 +03:00
fix(types): align runWhen type with runtime behavior in InterceptorManager (#7529)
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 <jasonsaayman@gmail.com>
This commit is contained in:
+2
-2
@@ -629,7 +629,7 @@ declare namespace axios {
|
||||
|
||||
interface AxiosInterceptorOptions {
|
||||
synchronous?: boolean;
|
||||
runWhen?: (config: InternalAxiosRequestConfig) => boolean;
|
||||
runWhen?: ((config: InternalAxiosRequestConfig) => boolean) | null;
|
||||
}
|
||||
|
||||
type AxiosInterceptorFulfilled<T> = (value: T) => T | Promise<T>;
|
||||
@@ -650,7 +650,7 @@ declare namespace axios {
|
||||
fulfilled: AxiosInterceptorFulfilled<T>;
|
||||
rejected?: AxiosInterceptorRejected;
|
||||
synchronous: boolean;
|
||||
runWhen?: (config: AxiosRequestConfig) => boolean;
|
||||
runWhen?: ((config: InternalAxiosRequestConfig) => boolean) | null;
|
||||
}
|
||||
|
||||
interface AxiosInterceptorManager<V> {
|
||||
|
||||
Vendored
+2
-2
@@ -639,7 +639,7 @@ export interface CancelTokenSource {
|
||||
|
||||
export interface AxiosInterceptorOptions {
|
||||
synchronous?: boolean;
|
||||
runWhen?: (config: InternalAxiosRequestConfig) => boolean;
|
||||
runWhen?: ((config: InternalAxiosRequestConfig) => boolean) | null;
|
||||
}
|
||||
|
||||
type AxiosInterceptorFulfilled<T> = (value: T) => T | Promise<T>;
|
||||
@@ -660,7 +660,7 @@ interface AxiosInterceptorHandler<T> {
|
||||
fulfilled: AxiosInterceptorFulfilled<T>;
|
||||
rejected?: AxiosInterceptorRejected;
|
||||
synchronous: boolean;
|
||||
runWhen: (config: AxiosRequestConfig) => boolean | null;
|
||||
runWhen?: ((config: InternalAxiosRequestConfig) => boolean) | null;
|
||||
}
|
||||
|
||||
export interface AxiosInterceptorManager<V> {
|
||||
|
||||
Reference in New Issue
Block a user