index.d.ts 3.2 KB
Newer Older
1
export interface AxiosTransformer {
2 3
  (data: any): any;
}
4

5 6 7 8 9 10 11 12 13
export interface AxiosAdapter {
  (config: AxiosRequestConfig): AxiosPromise;
}

export interface AxiosBasicCredentials {
  username: string;
  password: string;
}

14 15 16 17 18
export interface AxiosProxyConfig {
  host: string;
  port: number;
}

19 20 21 22
export interface AxiosRequestConfig {
  url?: string;
  method?: string;
  baseURL?: string;
23 24
  transformRequest?: AxiosTransformer | AxiosTransformer[];
  transformResponse?: AxiosTransformer | AxiosTransformer[];
25 26 27 28 29 30
  headers?: any;
  params?: any;
  paramsSerializer?: (params: any) => string;
  data?: any;
  timeout?: number;
  withCredentials?: boolean;
31 32
  adapter?: AxiosAdapter;
  auth?: AxiosBasicCredentials;
33 34 35
  responseType?: string;
  xsrfCookieName?: string;
  xsrfHeaderName?: string;
36 37
  onUploadProgress?: (progressEvent: any) => void;
  onDownloadProgress?: (progressEvent: any) => void;
38 39 40 41 42
  maxContentLength?: number;
  validateStatus?: (status: number) => boolean;
  maxRedirects?: number;
  httpAgent?: any;
  httpsAgent?: any;
43
  proxy?: AxiosProxyConfig;
44
  cancelToken?: CancelToken;
45
}
46

47 48 49 50 51 52 53
export interface AxiosResponse {
  data: any;
  status: number;
  statusText: string;
  headers: any;
  config: AxiosRequestConfig;
}
N
Nick Uraltsev 已提交
54

55 56 57 58 59 60 61 62 63
export interface AxiosError extends Error {
  config: AxiosRequestConfig;
  code?: string;
  response?: AxiosResponse;
}

export interface AxiosPromise extends Promise<AxiosResponse> {
}

64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
export interface CancelStatic {
  new (message?: string): Cancel;
}

export interface Cancel {
  message: string;
}

export interface Canceler {
  (message?: string): void;
}

export interface CancelTokenStatic {
  new (executor: (cancel: Canceler) => void): CancelToken;
  source(): CancelTokenSource;
}

export interface CancelToken {
  promise: Promise<Cancel>;
  reason?: Cancel;
  throwIfRequested(): void;
}

export interface CancelTokenSource {
  token: CancelToken;
  cancel: Canceler;
}

92
export interface AxiosInterceptorManager<V> {
93 94 95 96
  use(onFulfilled: (value: V) => V | Promise<V>, onRejected?: (error: any) => any): number;
  eject(id: number): void;
}

97 98
export interface AxiosInstance {
  defaults: AxiosRequestConfig;
99
  interceptors: {
100 101
    request: AxiosInterceptorManager<AxiosRequestConfig>;
    response: AxiosInterceptorManager<AxiosResponse>;
102 103 104 105 106 107 108 109
  };
  request(config: AxiosRequestConfig): AxiosPromise;
  get(url: string, config?: AxiosRequestConfig): AxiosPromise;
  delete(url: string, config?: AxiosRequestConfig): AxiosPromise;
  head(url: string, config?: AxiosRequestConfig): AxiosPromise;
  post(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise;
  put(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise;
  patch(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise;
110 111
}

112
export interface AxiosStatic extends AxiosInstance {
113 114
  (config: AxiosRequestConfig): AxiosPromise;
  (url: string, config?: AxiosRequestConfig): AxiosPromise;
115
  create(config?: AxiosRequestConfig): AxiosInstance;
116
  Cancel: CancelStatic;
N
Nick Uraltsev 已提交
117 118
  CancelToken: CancelTokenStatic;
  isCancel(value: any): boolean;
119 120
  all<T>(values: (T | Promise<T>)[]): Promise<T[]>;
  spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
121
}
122 123 124 125

declare const Axios: AxiosStatic;

export default Axios;