|
| 1 | +declare module 'axios/index' {} |
| 2 | + |
| 3 | +declare module 'axios' { |
| 4 | + export interface AxiosTransformer { |
| 5 | + (data: any, headers?: any): any; |
| 6 | + } |
| 7 | + |
| 8 | + export interface AxiosAdapter { |
| 9 | + (config: AxiosRequestConfig): AxiosPromise<any>; |
| 10 | + } |
| 11 | + |
| 12 | + export interface AxiosBasicCredentials { |
| 13 | + username: string; |
| 14 | + password: string; |
| 15 | + } |
| 16 | + |
| 17 | + export interface AxiosProxyConfig { |
| 18 | + host: string; |
| 19 | + port: number; |
| 20 | + auth?: { |
| 21 | + username: string; |
| 22 | + password: string; |
| 23 | + }; |
| 24 | + protocol?: string; |
| 25 | + } |
| 26 | + |
| 27 | + export type Method = |
| 28 | + | 'get' | 'GET' |
| 29 | + | 'delete' | 'DELETE' |
| 30 | + | 'head' | 'HEAD' |
| 31 | + | 'options' | 'OPTIONS' |
| 32 | + | 'post' | 'POST' |
| 33 | + | 'put' | 'PUT' |
| 34 | + | 'patch' | 'PATCH' |
| 35 | + | 'link' | 'LINK' |
| 36 | + | 'unlink' | 'UNLINK'; |
| 37 | + |
| 38 | + export type ResponseType = |
| 39 | + | 'arraybuffer' |
| 40 | + | 'blob' |
| 41 | + | 'document' |
| 42 | + | 'json' |
| 43 | + | 'text' |
| 44 | + | 'stream'; |
| 45 | + |
| 46 | + // Tipos de cabeçalho |
| 47 | + export type RawAxiosRequestHeaders = Record<string, any>; |
| 48 | + export type RawAxiosResponseHeaders = Record<string, any>; |
| 49 | + export interface AxiosHeaders extends Record<string, any> { |
| 50 | + set(headerName: string, value: string): AxiosHeaders; |
| 51 | + get(headerName: string): string | undefined; |
| 52 | + delete(headerName: string): boolean; |
| 53 | + clear(): AxiosHeaders; |
| 54 | + toJSON(): Record<string, any>; |
| 55 | + [key: string]: any; |
| 56 | + } |
| 57 | + |
| 58 | + export interface AxiosRequestConfig { |
| 59 | + url?: string; |
| 60 | + method?: Method; |
| 61 | + baseURL?: string; |
| 62 | + transformRequest?: AxiosTransformer | AxiosTransformer[]; |
| 63 | + transformResponse?: AxiosTransformer | AxiosTransformer[]; |
| 64 | + headers?: RawAxiosRequestHeaders; |
| 65 | + params?: any; |
| 66 | + paramsSerializer?: (params: any) => string; |
| 67 | + data?: any; |
| 68 | + timeout?: number; |
| 69 | + timeoutErrorMessage?: string; |
| 70 | + withCredentials?: boolean; |
| 71 | + adapter?: AxiosAdapter; |
| 72 | + auth?: AxiosBasicCredentials; |
| 73 | + responseType?: ResponseType; |
| 74 | + responseEncoding?: string; |
| 75 | + xsrfCookieName?: string; |
| 76 | + xsrfHeaderName?: string; |
| 77 | + onUploadProgress?: (progressEvent: any) => void; |
| 78 | + onDownloadProgress?: (progressEvent: any) => void; |
| 79 | + maxContentLength?: number; |
| 80 | + maxBodyLength?: number; |
| 81 | + validateStatus?: (status: number) => boolean; |
| 82 | + maxRedirects?: number; |
| 83 | + socketPath?: string | null; |
| 84 | + httpAgent?: any; |
| 85 | + httpsAgent?: any; |
| 86 | + proxy?: AxiosProxyConfig | false; |
| 87 | + cancelToken?: CancelToken; |
| 88 | + decompress?: boolean; |
| 89 | + transitional?: any; |
| 90 | + signal?: any; |
| 91 | + insecureHTTPParser?: boolean; |
| 92 | + [key: string]: any; // Para permitir qualquer propriedade adicional |
| 93 | + } |
| 94 | + |
| 95 | + export interface InternalAxiosRequestConfig extends AxiosRequestConfig { |
| 96 | + headers: AxiosHeaders | RawAxiosRequestHeaders; |
| 97 | + [key: string]: any; // Para permitir propriedades adicionais como 'tracing' |
| 98 | + } |
| 99 | + |
| 100 | + export interface AxiosResponse<T = any> { |
| 101 | + data: T; |
| 102 | + status: number; |
| 103 | + statusText: string; |
| 104 | + headers: RawAxiosResponseHeaders; |
| 105 | + config: AxiosRequestConfig; |
| 106 | + request?: any; |
| 107 | + } |
| 108 | + |
| 109 | + // Define AxiosError como uma classe para fazer instanceof funcionar |
| 110 | + export class AxiosError<T = any> extends Error { |
| 111 | + config: AxiosRequestConfig; |
| 112 | + code?: string; |
| 113 | + request?: any; |
| 114 | + response?: AxiosResponse<T>; |
| 115 | + isAxiosError: boolean; |
| 116 | + status?: number; |
| 117 | + |
| 118 | + constructor( |
| 119 | + message?: string, |
| 120 | + code?: string, |
| 121 | + config?: AxiosRequestConfig, |
| 122 | + request?: any, |
| 123 | + response?: AxiosResponse<T> |
| 124 | + ); |
| 125 | + |
| 126 | + toJSON(): object; |
| 127 | + |
| 128 | + // Métodos estáticos para criar instâncias de AxiosError |
| 129 | + static from<T = any>( |
| 130 | + error: Error, |
| 131 | + code?: string, |
| 132 | + config?: AxiosRequestConfig, |
| 133 | + request?: any, |
| 134 | + response?: AxiosResponse<T>, |
| 135 | + customProps?: Record<string, any> |
| 136 | + ): AxiosError<T>; |
| 137 | + } |
| 138 | + |
| 139 | + export interface AxiosPromise<T = any> extends Promise<AxiosResponse<T>> { |
| 140 | + } |
| 141 | + |
| 142 | + export interface CancelStatic { |
| 143 | + new (message?: string): Cancel; |
| 144 | + } |
| 145 | + |
| 146 | + export interface Cancel { |
| 147 | + message: string; |
| 148 | + } |
| 149 | + |
| 150 | + export interface Canceler { |
| 151 | + (message?: string): void; |
| 152 | + } |
| 153 | + |
| 154 | + export interface CancelTokenStatic { |
| 155 | + new (executor: (cancel: Canceler) => void): CancelToken; |
| 156 | + source(): CancelTokenSource; |
| 157 | + } |
| 158 | + |
| 159 | + export interface CancelToken { |
| 160 | + promise: Promise<Cancel>; |
| 161 | + reason?: Cancel; |
| 162 | + throwIfRequested(): void; |
| 163 | + } |
| 164 | + |
| 165 | + export interface CancelTokenSource { |
| 166 | + token: CancelToken; |
| 167 | + cancel: Canceler; |
| 168 | + } |
| 169 | + |
| 170 | + export interface AxiosInterceptorManager<V> { |
| 171 | + use(onFulfilled?: (value: V) => V | Promise<V>, onRejected?: (error: any) => any): number; |
| 172 | + eject(id: number): void; |
| 173 | + clear(): void; |
| 174 | + } |
| 175 | + |
| 176 | + export interface AxiosInstance { |
| 177 | + (config: AxiosRequestConfig): AxiosPromise; |
| 178 | + (url: string, config?: AxiosRequestConfig): AxiosPromise; |
| 179 | + defaults: AxiosRequestConfig; |
| 180 | + interceptors: { |
| 181 | + request: AxiosInterceptorManager<AxiosRequestConfig>; |
| 182 | + response: AxiosInterceptorManager<AxiosResponse>; |
| 183 | + }; |
| 184 | + getUri(config?: AxiosRequestConfig): string; |
| 185 | + request<T = any, R = AxiosResponse<T>>(config: AxiosRequestConfig): Promise<R>; |
| 186 | + get<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>; |
| 187 | + delete<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>; |
| 188 | + head<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>; |
| 189 | + options<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>; |
| 190 | + post<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>; |
| 191 | + put<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>; |
| 192 | + patch<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>; |
| 193 | + } |
| 194 | + |
| 195 | + export interface AxiosStatic extends AxiosInstance { |
| 196 | + create(config?: AxiosRequestConfig): AxiosInstance; |
| 197 | + Cancel: CancelStatic; |
| 198 | + CancelToken: CancelTokenStatic; |
| 199 | + isCancel(value: any): boolean; |
| 200 | + all<T>(values: (T | Promise<T>)[]): Promise<T[]>; |
| 201 | + spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R; |
| 202 | + isAxiosError(payload: any): payload is AxiosError; |
| 203 | + } |
| 204 | + |
| 205 | + const axios: AxiosStatic; |
| 206 | + |
| 207 | + export const AxiosError: { |
| 208 | + new <T = any>( |
| 209 | + message?: string, |
| 210 | + code?: string, |
| 211 | + config?: AxiosRequestConfig, |
| 212 | + request?: any, |
| 213 | + response?: AxiosResponse<T> |
| 214 | + ): AxiosError<T>; |
| 215 | + readonly prototype: AxiosError; |
| 216 | + readonly ERR_NETWORK: string; |
| 217 | + readonly ERR_BAD_REQUEST: string; |
| 218 | + readonly TIMEOUT_ERROR_CODE: string; |
| 219 | + readonly ERR_BAD_RESPONSE: string; |
| 220 | + readonly ERR_FR_TOO_MANY_REDIRECTS: string; |
| 221 | + readonly ERR_DEPRECATED: string; |
| 222 | + readonly ERR_BAD_OPTION_VALUE: string; |
| 223 | + readonly ERR_CANCELED: string; |
| 224 | + readonly ECONNABORTED: string; |
| 225 | + readonly ETIMEDOUT: string; |
| 226 | + from<T = any>( |
| 227 | + error: Error, |
| 228 | + code?: string, |
| 229 | + config?: AxiosRequestConfig, |
| 230 | + request?: any, |
| 231 | + response?: AxiosResponse<T>, |
| 232 | + customProps?: Record<string, any> |
| 233 | + ): AxiosError<T>; |
| 234 | + }; |
| 235 | + |
| 236 | + export default axios; |
| 237 | +} |
0 commit comments