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