Skip to content

Commit

Permalink
require interceptors to return values (#4874)
Browse files Browse the repository at this point in the history
Fixes #4873

Co-authored-by: Jay <jasonsaayman@gmail.com>
  • Loading branch information
jennings and jasonsaayman committed Sep 26, 2022
1 parent b0710bf commit 64906bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.d.ts
Expand Up @@ -343,7 +343,7 @@ export interface AxiosInterceptorOptions {
}

export interface AxiosInterceptorManager<V> {
use<T = V>(onFulfilled?: (value: V) => T | Promise<T>, onRejected?: (error: any) => any, options?: AxiosInterceptorOptions): number;
use(onFulfilled?: (value: V) => V | Promise<V>, onRejected?: (error: any) => any, options?: AxiosInterceptorOptions): number;
eject(id: number): void;
}

Expand Down
13 changes: 13 additions & 0 deletions test/typescript/axios.ts
Expand Up @@ -300,6 +300,19 @@ axios.interceptors.response.use(
(error: any) => Promise.reject(error)
);

const voidRequestInterceptorId = axios.interceptors.request.use(
// @ts-expect-error -- Must return an AxiosRequestConfig (or throw)
(_response) => {},
(error: any) => Promise.reject(error)
);
const voidResponseInterceptorId = axios.interceptors.response.use(
// @ts-expect-error -- Must return an AxiosResponse (or throw)
(_response) => {},
(error: any) => Promise.reject(error)
);
axios.interceptors.request.eject(voidRequestInterceptorId);
axios.interceptors.response.eject(voidResponseInterceptorId);

axios.interceptors.response.use((response: AxiosResponse) => response);
axios.interceptors.response.use((response: AxiosResponse) => Promise.resolve(response));

Expand Down

0 comments on commit 64906bd

Please sign in to comment.