Skip to content

Commit

Permalink
Exposing the Axios constructor in index.d.ts
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
  • Loading branch information
TimWolla committed Aug 31, 2020
1 parent 0d87655 commit ab71639
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions index.d.ts
Expand Up @@ -127,9 +127,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 @@ -146,15 +145,21 @@ 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;
}

declare const Axios: AxiosStatic;
declare const axios: AxiosStatic;

export default Axios;
export default axios;

0 comments on commit ab71639

Please sign in to comment.