index.d.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. export interface AxiosTransformer {
  2. (data: any): any;
  3. }
  4. export interface AxiosAdapter {
  5. (config: AxiosRequestConfig): AxiosPromise;
  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 {
  43. data: any;
  44. status: number;
  45. statusText: string;
  46. headers: any;
  47. config: AxiosRequestConfig;
  48. }
  49. export interface AxiosError extends Error {
  50. config: AxiosRequestConfig;
  51. code?: string;
  52. response?: AxiosResponse;
  53. }
  54. export interface Promise<V> {
  55. then<R1, R2>(onFulfilled: (value: V) => R1 | Promise<R1>, onRejected: (error: any) => R2 | Promise<R2>): Promise<R1 | R2>;
  56. then<R>(onFulfilled: (value: V) => R | Promise<R>): Promise<R>;
  57. catch<R>(onRejected: (error: any) => R | Promise<R>): Promise<R>;
  58. }
  59. export interface AxiosPromise extends Promise<AxiosResponse> {
  60. }
  61. export interface CancelStatic {
  62. new (message?: string): Cancel;
  63. }
  64. export interface Cancel {
  65. message: string;
  66. }
  67. export interface Canceler {
  68. (message?: string): void;
  69. }
  70. export interface CancelTokenStatic {
  71. new (executor: (cancel: Canceler) => void): CancelToken;
  72. source(): CancelTokenSource;
  73. }
  74. export interface CancelToken {
  75. promise: Promise<Cancel>;
  76. reason?: Cancel;
  77. throwIfRequested(): void;
  78. }
  79. export interface CancelTokenSource {
  80. token: CancelToken;
  81. cancel: Canceler;
  82. }
  83. export interface AxiosInterceptorManager<V> {
  84. use(onFulfilled: (value: V) => V | Promise<V>, onRejected?: (error: any) => any): number;
  85. eject(id: number): void;
  86. }
  87. export interface AxiosInstance {
  88. defaults: AxiosRequestConfig;
  89. interceptors: {
  90. request: AxiosInterceptorManager<AxiosRequestConfig>;
  91. response: AxiosInterceptorManager<AxiosResponse>;
  92. };
  93. request(config: AxiosRequestConfig): AxiosPromise;
  94. get(url: string, config?: AxiosRequestConfig): AxiosPromise;
  95. delete(url: string, config?: AxiosRequestConfig): AxiosPromise;
  96. head(url: string, config?: AxiosRequestConfig): AxiosPromise;
  97. post(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise;
  98. put(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise;
  99. patch(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise;
  100. }
  101. export interface AxiosStatic extends AxiosInstance {
  102. (config: AxiosRequestConfig): AxiosPromise;
  103. (url: string, config?: AxiosRequestConfig): AxiosPromise;
  104. create(config?: AxiosRequestConfig): AxiosInstance;
  105. Cancel: CancelStatic;
  106. CancelToken: CancelTokenStatic;
  107. isCancel(value: any): boolean;
  108. all<T>(values: (T | Promise<T>)[]): Promise<T[]>;
  109. spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
  110. }
  111. declare const Axios: AxiosStatic;
  112. export default Axios;