index.d.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. // TypeScript Version: 3.0
  2. export type AxiosRequestHeaders = Record<string, string>;
  3. export type AxiosResponseHeaders = Record<string, string> & {
  4. "set-cookie"?: string[]
  5. };
  6. export interface AxiosRequestTransformer {
  7. (data: any, headers?: AxiosRequestHeaders): any;
  8. }
  9. export interface AxiosResponseTransformer {
  10. (data: any, headers?: AxiosResponseHeaders): any;
  11. }
  12. export interface AxiosAdapter {
  13. (config: AxiosRequestConfig): AxiosPromise;
  14. }
  15. export interface AxiosBasicCredentials {
  16. username: string;
  17. password: string;
  18. }
  19. export interface AxiosProxyConfig {
  20. host: string;
  21. port: number;
  22. auth?: {
  23. username: string;
  24. password: string;
  25. };
  26. protocol?: string;
  27. }
  28. export type Method =
  29. | 'get' | 'GET'
  30. | 'delete' | 'DELETE'
  31. | 'head' | 'HEAD'
  32. | 'options' | 'OPTIONS'
  33. | 'post' | 'POST'
  34. | 'put' | 'PUT'
  35. | 'patch' | 'PATCH'
  36. | 'purge' | 'PURGE'
  37. | 'link' | 'LINK'
  38. | 'unlink' | 'UNLINK';
  39. export type ResponseType =
  40. | 'arraybuffer'
  41. | 'blob'
  42. | 'document'
  43. | 'json'
  44. | 'text'
  45. | 'stream';
  46. export interface TransitionalOptions {
  47. silentJSONParsing?: boolean;
  48. forcedJSONParsing?: boolean;
  49. clarifyTimeoutError?: boolean;
  50. }
  51. export interface AxiosRequestConfig<D = any> {
  52. url?: string;
  53. method?: Method;
  54. baseURL?: string;
  55. transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
  56. transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
  57. headers?: AxiosRequestHeaders;
  58. params?: any;
  59. paramsSerializer?: (params: any) => string;
  60. data?: D;
  61. timeout?: number;
  62. timeoutErrorMessage?: string;
  63. withCredentials?: boolean;
  64. adapter?: AxiosAdapter;
  65. auth?: AxiosBasicCredentials;
  66. responseType?: ResponseType;
  67. xsrfCookieName?: string;
  68. xsrfHeaderName?: string;
  69. onUploadProgress?: (progressEvent: any) => void;
  70. onDownloadProgress?: (progressEvent: any) => void;
  71. maxContentLength?: number;
  72. validateStatus?: ((status: number) => boolean) | null;
  73. maxBodyLength?: number;
  74. maxRedirects?: number;
  75. socketPath?: string | null;
  76. httpAgent?: any;
  77. httpsAgent?: any;
  78. proxy?: AxiosProxyConfig | false;
  79. cancelToken?: CancelToken;
  80. decompress?: boolean;
  81. transitional?: TransitionalOptions;
  82. signal?: AbortSignal;
  83. insecureHTTPParser?: boolean;
  84. }
  85. export interface HeadersDefaults {
  86. common: AxiosRequestHeaders;
  87. delete: AxiosRequestHeaders;
  88. get: AxiosRequestHeaders;
  89. head: AxiosRequestHeaders;
  90. post: AxiosRequestHeaders;
  91. put: AxiosRequestHeaders;
  92. patch: AxiosRequestHeaders;
  93. options?: AxiosRequestHeaders;
  94. purge?: AxiosRequestHeaders;
  95. link?: AxiosRequestHeaders;
  96. unlink?: AxiosRequestHeaders;
  97. }
  98. export interface AxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
  99. headers: HeadersDefaults;
  100. }
  101. export interface AxiosResponse<T = any, D = any> {
  102. data: T;
  103. status: number;
  104. statusText: string;
  105. headers: AxiosResponseHeaders;
  106. config: AxiosRequestConfig<D>;
  107. request?: any;
  108. }
  109. export interface AxiosError<T = any, D = any> extends Error {
  110. config: AxiosRequestConfig<D>;
  111. code?: string;
  112. request?: any;
  113. response?: AxiosResponse<T, D>;
  114. isAxiosError: boolean;
  115. toJSON: () => object;
  116. }
  117. export interface AxiosPromise<T = any> extends Promise<AxiosResponse<T>> {
  118. }
  119. export interface CancelStatic {
  120. new (message?: string): Cancel;
  121. }
  122. export interface Cancel {
  123. message: string;
  124. }
  125. export interface Canceler {
  126. (message?: string): void;
  127. }
  128. export interface CancelTokenStatic {
  129. new (executor: (cancel: Canceler) => void): CancelToken;
  130. source(): CancelTokenSource;
  131. }
  132. export interface CancelToken {
  133. promise: Promise<Cancel>;
  134. reason?: Cancel;
  135. throwIfRequested(): void;
  136. }
  137. export interface CancelTokenSource {
  138. token: CancelToken;
  139. cancel: Canceler;
  140. }
  141. export interface AxiosInterceptorManager<V> {
  142. use<T = V>(onFulfilled?: (value: V) => T | Promise<T>, onRejected?: (error: any) => any): number;
  143. eject(id: number): void;
  144. }
  145. export class Axios {
  146. constructor(config?: AxiosRequestConfig);
  147. defaults: AxiosDefaults;
  148. interceptors: {
  149. request: AxiosInterceptorManager<AxiosRequestConfig>;
  150. response: AxiosInterceptorManager<AxiosResponse>;
  151. };
  152. getUri(config?: AxiosRequestConfig): string;
  153. request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
  154. get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
  155. delete<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
  156. head<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
  157. options<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
  158. post<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
  159. put<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
  160. patch<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
  161. }
  162. export interface AxiosInstance extends Axios {
  163. (config: AxiosRequestConfig): AxiosPromise;
  164. (url: string, config?: AxiosRequestConfig): AxiosPromise;
  165. }
  166. export interface AxiosStatic extends AxiosInstance {
  167. create(config?: AxiosRequestConfig): AxiosInstance;
  168. Cancel: CancelStatic;
  169. CancelToken: CancelTokenStatic;
  170. Axios: typeof Axios;
  171. readonly VERSION: string;
  172. isCancel(value: any): boolean;
  173. all<T>(values: Array<T | Promise<T>>): Promise<T[]>;
  174. spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
  175. isAxiosError(payload: any): payload is AxiosError;
  176. }
  177. declare const axios: AxiosStatic;
  178. export default axios;