Skip to content

Commit 8d1271b

Browse files
tiborpilzTibor PilzjasonsaaymanCopilot
authored
fix(types): add handlers to AxiosInterceptorManager interface (#5551)
* fix(types): add handlers to AxiosInterceptorManager interface * fix: runwhen should be optional Co-authored-by: Copilot <[email protected]> * chore: make handlers optional * chore: optional handlers --------- Co-authored-by: Tibor Pilz <[email protected]> Co-authored-by: Jay <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent f869434 commit 8d1271b

2 files changed

Lines changed: 40 additions & 4 deletions

File tree

index.d.cts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,14 +515,32 @@ declare namespace axios {
515515
runWhen?: (config: InternalAxiosRequestConfig) => boolean;
516516
}
517517

518-
type AxiosRequestInterceptorUse<T> = (onFulfilled?: ((value: T) => T | Promise<T>) | null, onRejected?: ((error: any) => any) | null, options?: AxiosInterceptorOptions) => number;
518+
type AxiosInterceptorFulfilled<T> = (value: T) => T | Promise<T>;
519+
type AxiosInterceptorRejected = (error: any) => any;
519520

520-
type AxiosResponseInterceptorUse<T> = (onFulfilled?: ((value: T) => T | Promise<T>) | null, onRejected?: ((error: any) => any) | null) => number;
521+
type AxiosRequestInterceptorUse<T> = (
522+
onFulfilled?: AxiosInterceptorFulfilled<T> | null,
523+
onRejected?: AxiosInterceptorRejected | null,
524+
options?: AxiosInterceptorOptions
525+
) => number;
526+
527+
type AxiosResponseInterceptorUse<T> = (
528+
onFulfilled?: AxiosInterceptorFulfilled<T> | null,
529+
onRejected?: AxiosInterceptorRejected | null
530+
) => number;
531+
532+
interface AxiosInterceptorHandler<T> {
533+
fulfilled: AxiosInterceptorFulfilled<T>;
534+
rejected?: AxiosInterceptorRejected;
535+
synchronous: boolean;
536+
runWhen?: (config: AxiosRequestConfig) => boolean;
537+
}
521538

522539
interface AxiosInterceptorManager<V> {
523540
use: V extends AxiosResponse ? AxiosResponseInterceptorUse<V> : AxiosRequestInterceptorUse<V>;
524541
eject(id: number): void;
525542
clear(): void;
543+
handlers?: Array<AxiosInterceptorHandler<V>>;
526544
}
527545

528546
interface AxiosInstance extends Axios {

index.d.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,14 +494,32 @@ export interface AxiosInterceptorOptions {
494494
runWhen?: (config: InternalAxiosRequestConfig) => boolean;
495495
}
496496

497-
type AxiosRequestInterceptorUse<T> = (onFulfilled?: ((value: T) => T | Promise<T>) | null, onRejected?: ((error: any) => any) | null, options?: AxiosInterceptorOptions) => number;
497+
type AxiosInterceptorFulfilled<T> = (value: T) => T | Promise<T>;
498+
type AxiosInterceptorRejected = (error: any) => any;
498499

499-
type AxiosResponseInterceptorUse<T> = (onFulfilled?: ((value: T) => T | Promise<T>) | null, onRejected?: ((error: any) => any) | null) => number;
500+
type AxiosRequestInterceptorUse<T> = (
501+
onFulfilled?: AxiosInterceptorFulfilled<T> | null,
502+
onRejected?: AxiosInterceptorRejected | null,
503+
options?: AxiosInterceptorOptions
504+
) => number;
505+
506+
type AxiosResponseInterceptorUse<T> = (
507+
onFulfilled?: AxiosInterceptorFulfilled<T> | null,
508+
onRejected?: AxiosInterceptorRejected | null
509+
) => number;
510+
511+
interface AxiosInterceptorHandler<T> {
512+
fulfilled: AxiosInterceptorFulfilled<T>;
513+
rejected?: AxiosInterceptorRejected;
514+
synchronous: boolean;
515+
runWhen: (config: AxiosRequestConfig) => boolean | null;
516+
}
500517

501518
export interface AxiosInterceptorManager<V> {
502519
use: V extends AxiosResponse ? AxiosResponseInterceptorUse<V> : AxiosRequestInterceptorUse<V>;
503520
eject(id: number): void;
504521
clear(): void;
522+
handlers?: Array<AxiosInterceptorHandler<V>>;
505523
}
506524

507525
export class Axios {

0 commit comments

Comments
 (0)