index.d.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. auth?: {
  15. username: string;
  16. password:string;
  17. };
  18. protocol?: string;
  19. }
  20. export type Method =
  21. | 'get' | 'GET'
  22. | 'delete' | 'DELETE'
  23. | 'head' | 'HEAD'
  24. | 'options' | 'OPTIONS'
  25. | 'post' | 'POST'
  26. | 'put' | 'PUT'
  27. | 'patch' | 'PATCH'
  28. | 'link' | 'LINK'
  29. | 'unlink' | 'UNLINK'
  30. export type ResponseType =
  31. | 'arraybuffer'
  32. | 'blob'
  33. | 'document'
  34. | 'json'
  35. | 'text'
  36. | 'stream'
  37. export interface AxiosRequestConfig {
  38. url?: string;
  39. method?: Method;
  40. baseURL?: string;
  41. transformRequest?: AxiosTransformer | AxiosTransformer[];
  42. transformResponse?: AxiosTransformer | AxiosTransformer[];
  43. headers?: any;
  44. params?: any;
  45. paramsSerializer?: (params: any) => string;
  46. data?: any;
  47. timeout?: number;
  48. timeoutErrorMessage?: string;
  49. withCredentials?: boolean;
  50. adapter?: AxiosAdapter;
  51. auth?: AxiosBasicCredentials;
  52. responseType?: ResponseType;
  53. xsrfCookieName?: string;
  54. xsrfHeaderName?: string;
  55. onUploadProgress?: (progressEvent: any) => void;
  56. onDownloadProgress?: (progressEvent: any) => void;
  57. maxContentLength?: number;
  58. validateStatus?: (status: number) => boolean;
  59. maxRedirects?: number;
  60. socketPath?: string | null;
  61. httpAgent?: any;
  62. httpsAgent?: any;
  63. proxy?: AxiosProxyConfig | false;
  64. cancelToken?: CancelToken;
  65. }
  66. export interface AxiosResponse<T = any> {
  67. data: T;
  68. status: number;
  69. statusText: string;
  70. headers: any;
  71. config: AxiosRequestConfig;
  72. request?: any;
  73. }
  74. export interface AxiosError<T = any> extends Error {
  75. config: AxiosRequestConfig;
  76. code?: string;
  77. request?: any;
  78. response?: AxiosResponse<T>;
  79. isAxiosError: boolean;
  80. toJSON: () => object;
  81. }
  82. export interface AxiosPromise<T = any> extends Promise<AxiosResponse<T>> {
  83. }
  84. export interface CancelStatic {
  85. new (message?: string): Cancel;
  86. }
  87. export interface Cancel {
  88. message: string;
  89. }
  90. export interface Canceler {
  91. (message?: string): void;
  92. }
  93. export interface CancelTokenStatic {
  94. new (executor: (cancel: Canceler) => void): CancelToken;
  95. source(): CancelTokenSource;
  96. }
  97. export interface CancelToken {
  98. promise: Promise<Cancel>;
  99. reason?: Cancel;
  100. throwIfRequested(): void;
  101. }
  102. export interface CancelTokenSource {
  103. token: CancelToken;
  104. cancel: Canceler;
  105. }
  106. export interface AxiosInterceptorManager<V> {
  107. use(onFulfilled?: (value: V) => V | Promise<V>, onRejected?: (error: any) => any): number;
  108. eject(id: number): void;
  109. }
  110. export interface AxiosInstance {
  111. (config: AxiosRequestConfig): AxiosPromise;
  112. (url: string, config?: AxiosRequestConfig): AxiosPromise;
  113. defaults: AxiosRequestConfig;
  114. interceptors: {
  115. request: AxiosInterceptorManager<AxiosRequestConfig>;
  116. response: AxiosInterceptorManager<AxiosResponse>;
  117. };
  118. getUri(config?: AxiosRequestConfig): string;
  119. request<T = any, R = AxiosResponse<T>> (config: AxiosRequestConfig): Promise<R>;
  120. get<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
  121. delete<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
  122. head<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
  123. options<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
  124. post<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
  125. put<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
  126. patch<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
  127. }
  128. export interface AxiosStatic extends AxiosInstance {
  129. create(config?: AxiosRequestConfig): AxiosInstance;
  130. Cancel: CancelStatic;
  131. CancelToken: CancelTokenStatic;
  132. isCancel(value: any): boolean;
  133. all<T>(values: (T | Promise<T>)[]): Promise<T[]>;
  134. spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
  135. }
  136. declare const Axios: AxiosStatic;
  137. export default Axios;