From 8d1271b49fc226ed7defd07cd577bd69a55bb13a Mon Sep 17 00:00:00 2001 From: Tibor Pilz Date: Tue, 30 Dec 2025 12:58:26 +0100 Subject: [PATCH] fix(types): add handlers to AxiosInterceptorManager interface (#5551) * fix(types): add handlers to AxiosInterceptorManager interface * fix: runwhen should be optional Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore: make handlers optional * chore: optional handlers --------- Co-authored-by: Tibor Pilz Co-authored-by: Jay Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- index.d.cts | 22 ++++++++++++++++++++-- index.d.ts | 22 ++++++++++++++++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/index.d.cts b/index.d.cts index e3a06a37..4be32f9c 100644 --- a/index.d.cts +++ b/index.d.cts @@ -515,14 +515,32 @@ declare namespace axios { runWhen?: (config: InternalAxiosRequestConfig) => boolean; } - type AxiosRequestInterceptorUse = (onFulfilled?: ((value: T) => T | Promise) | null, onRejected?: ((error: any) => any) | null, options?: AxiosInterceptorOptions) => number; + type AxiosInterceptorFulfilled = (value: T) => T | Promise; + type AxiosInterceptorRejected = (error: any) => any; - type AxiosResponseInterceptorUse = (onFulfilled?: ((value: T) => T | Promise) | null, onRejected?: ((error: any) => any) | null) => number; + type AxiosRequestInterceptorUse = ( + onFulfilled?: AxiosInterceptorFulfilled | null, + onRejected?: AxiosInterceptorRejected | null, + options?: AxiosInterceptorOptions + ) => number; + + type AxiosResponseInterceptorUse = ( + onFulfilled?: AxiosInterceptorFulfilled | null, + onRejected?: AxiosInterceptorRejected | null + ) => number; + + interface AxiosInterceptorHandler { + fulfilled: AxiosInterceptorFulfilled; + rejected?: AxiosInterceptorRejected; + synchronous: boolean; + runWhen?: (config: AxiosRequestConfig) => boolean; + } interface AxiosInterceptorManager { use: V extends AxiosResponse ? AxiosResponseInterceptorUse : AxiosRequestInterceptorUse; eject(id: number): void; clear(): void; + handlers?: Array>; } interface AxiosInstance extends Axios { diff --git a/index.d.ts b/index.d.ts index ff29215f..c562d9c0 100644 --- a/index.d.ts +++ b/index.d.ts @@ -494,14 +494,32 @@ export interface AxiosInterceptorOptions { runWhen?: (config: InternalAxiosRequestConfig) => boolean; } -type AxiosRequestInterceptorUse = (onFulfilled?: ((value: T) => T | Promise) | null, onRejected?: ((error: any) => any) | null, options?: AxiosInterceptorOptions) => number; +type AxiosInterceptorFulfilled = (value: T) => T | Promise; +type AxiosInterceptorRejected = (error: any) => any; -type AxiosResponseInterceptorUse = (onFulfilled?: ((value: T) => T | Promise) | null, onRejected?: ((error: any) => any) | null) => number; +type AxiosRequestInterceptorUse = ( + onFulfilled?: AxiosInterceptorFulfilled | null, + onRejected?: AxiosInterceptorRejected | null, + options?: AxiosInterceptorOptions +) => number; + +type AxiosResponseInterceptorUse = ( + onFulfilled?: AxiosInterceptorFulfilled | null, + onRejected?: AxiosInterceptorRejected | null +) => number; + +interface AxiosInterceptorHandler { + fulfilled: AxiosInterceptorFulfilled; + rejected?: AxiosInterceptorRejected; + synchronous: boolean; + runWhen: (config: AxiosRequestConfig) => boolean | null; +} export interface AxiosInterceptorManager { use: V extends AxiosResponse ? AxiosResponseInterceptorUse : AxiosRequestInterceptorUse; eject(id: number): void; clear(): void; + handlers?: Array>; } export class Axios {