index.d.ts 4.4 KB

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