index.d.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. export interface AxiosTransformer {
  2. (data: any, headers?: any): any;
  3. }
  4. export interface AxiosAdapter {
  5. (config: AxiosRequestConfig): AxiosPromise<any>;
  6. }
  7. export interface AxiosBasicCredentials {
  8. username: string;
  9. password: string;
  10. }
  11. export interface AxiosProxyConfig {
  12. host: string;
  13. port: number;
  14. }
  15. export interface AxiosRequestConfig {
  16. url?: string;
  17. method?: string;
  18. baseURL?: string;
  19. transformRequest?: AxiosTransformer | AxiosTransformer[];
  20. transformResponse?: AxiosTransformer | AxiosTransformer[];
  21. headers?: any;
  22. params?: any;
  23. paramsSerializer?: (params: any) => string;
  24. data?: any;
  25. timeout?: number;
  26. withCredentials?: boolean;
  27. adapter?: AxiosAdapter;
  28. auth?: AxiosBasicCredentials;
  29. responseType?: string;
  30. xsrfCookieName?: string;
  31. xsrfHeaderName?: string;
  32. onUploadProgress?: (progressEvent: any) => void;
  33. onDownloadProgress?: (progressEvent: any) => void;
  34. maxContentLength?: number;
  35. validateStatus?: (status: number) => boolean;
  36. maxRedirects?: number;
  37. httpAgent?: any;
  38. httpsAgent?: any;
  39. proxy?: AxiosProxyConfig;
  40. cancelToken?: CancelToken;
  41. }
  42. export interface AxiosResponse<T = any> {
  43. data: T;
  44. status: number;
  45. statusText: string;
  46. headers: any;
  47. config: AxiosRequestConfig;
  48. request?: any;
  49. }
  50. export interface AxiosError extends Error {
  51. config: AxiosRequestConfig;
  52. code?: string;
  53. request?: any;
  54. response?: AxiosResponse;
  55. }
  56. export interface AxiosPromise<T = any> extends Promise<AxiosResponse<T>> {
  57. }
  58. export interface CancelStatic {
  59. new (message?: string): Cancel;
  60. }
  61. export interface Cancel {
  62. message: string;
  63. }
  64. export interface Canceler {
  65. (message?: string): void;
  66. }
  67. export interface CancelTokenStatic {
  68. new (executor: (cancel: Canceler) => void): CancelToken;
  69. source(): CancelTokenSource;
  70. }
  71. export interface CancelToken {
  72. promise: Promise<Cancel>;
  73. reason?: Cancel;
  74. throwIfRequested(): void;
  75. }
  76. export interface CancelTokenSource {
  77. token: CancelToken;
  78. cancel: Canceler;
  79. }
  80. export interface AxiosInterceptorManager<V> {
  81. use(onFulfilled?: (value: V) => V | Promise<V>, onRejected?: (error: any) => any): number;
  82. eject(id: number): void;
  83. }
  84. export interface AxiosInstance {
  85. defaults: AxiosRequestConfig;
  86. interceptors: {
  87. request: AxiosInterceptorManager<AxiosRequestConfig>;
  88. response: AxiosInterceptorManager<AxiosResponse>;
  89. };
  90. request<T = any>(config: AxiosRequestConfig): AxiosPromise<T>;
  91. get<T = any>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>;
  92. delete(url: string, config?: AxiosRequestConfig): AxiosPromise;
  93. head(url: string, config?: AxiosRequestConfig): AxiosPromise;
  94. post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
  95. put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
  96. patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
  97. }
  98. export interface AxiosStatic extends AxiosInstance {
  99. (config: AxiosRequestConfig): AxiosPromise;
  100. (url: string, config?: AxiosRequestConfig): AxiosPromise;
  101. create(config?: AxiosRequestConfig): AxiosInstance;
  102. Cancel: CancelStatic;
  103. CancelToken: CancelTokenStatic;
  104. isCancel(value: any): boolean;
  105. all<T>(values: (T | Promise<T>)[]): Promise<T[]>;
  106. spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
  107. }
  108. declare const Axios: AxiosStatic;
  109. export default Axios;