Skip to content

Commit

Permalink
Exposing the Axios constructor in index.d.ts (#2872)
Browse files Browse the repository at this point in the history
This patch allows TypeScript users to extend the `Axios` class without
the type checker complaining.

see 7548f2f

Co-authored-by: Jay <jasonsaayman@gmail.com>
  • Loading branch information
TimWolla and jasonsaayman committed Sep 5, 2021
1 parent c26762f commit 4f25380
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions index.d.ts
Expand Up @@ -134,9 +134,8 @@ export interface AxiosInterceptorManager<V> {
eject(id: number): void;
}

export interface AxiosInstance {
(config: AxiosRequestConfig): AxiosPromise;
(url: string, config?: AxiosRequestConfig): AxiosPromise;
export class Axios {
constructor(config?: AxiosRequestConfig);
defaults: AxiosRequestConfig;
interceptors: {
request: AxiosInterceptorManager<AxiosRequestConfig>;
Expand All @@ -153,10 +152,16 @@ export interface AxiosInstance {
patch<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
}

export interface AxiosInstance extends Axios {
(config: AxiosRequestConfig): AxiosPromise;
(url: string, config?: AxiosRequestConfig): AxiosPromise;
}

export interface AxiosStatic extends AxiosInstance {
create(config?: AxiosRequestConfig): AxiosInstance;
Cancel: CancelStatic;
CancelToken: CancelTokenStatic;
Axios: typeof Axios;
isCancel(value: any): boolean;
all<T>(values: (T | Promise<T>)[]): Promise<T[]>;
spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
Expand Down

0 comments on commit 4f25380

Please sign in to comment.