mirror of
https://github.com/tenrok/axios.git
synced 2026-06-23 20:40:40 +03:00
fix(types): renamed RawAxiosRequestConfig back to AxiosRequestConfig; (#5486)
This commit is contained in:
+46
-43
@@ -4,13 +4,9 @@ interface RawAxiosHeaders {
|
|||||||
[key: string]: AxiosHeaderValue;
|
[key: string]: AxiosHeaderValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
type MethodsHeaders = {
|
type MethodsHeaders = Partial<{
|
||||||
[Key in axios.Method as Lowercase<Key>]: AxiosHeaders;
|
[Key in axios.Method as Lowercase<Key>]: AxiosHeaders;
|
||||||
};
|
} & {common: AxiosHeaders}>;
|
||||||
|
|
||||||
interface CommonHeaders {
|
|
||||||
common: AxiosHeaders;
|
|
||||||
}
|
|
||||||
|
|
||||||
type AxiosHeaderMatcher = (this: AxiosHeaders, value: string, name: string, headers: RawAxiosHeaders) => boolean;
|
type AxiosHeaderMatcher = (this: AxiosHeaders, value: string, name: string, headers: RawAxiosHeaders) => boolean;
|
||||||
|
|
||||||
@@ -79,12 +75,12 @@ declare class AxiosError<T = unknown, D = any> extends Error {
|
|||||||
constructor(
|
constructor(
|
||||||
message?: string,
|
message?: string,
|
||||||
code?: string,
|
code?: string,
|
||||||
config?: axios.AxiosRequestConfig<D>,
|
config?: axios.InternalAxiosRequestConfig<D>,
|
||||||
request?: any,
|
request?: any,
|
||||||
response?: axios.AxiosResponse<T, D>
|
response?: axios.AxiosResponse<T, D>
|
||||||
);
|
);
|
||||||
|
|
||||||
config?: axios.AxiosRequestConfig<D>;
|
config?: axios.InternalAxiosRequestConfig<D>;
|
||||||
code?: string;
|
code?: string;
|
||||||
request?: any;
|
request?: any;
|
||||||
response?: axios.AxiosResponse<T, D>;
|
response?: axios.AxiosResponse<T, D>;
|
||||||
@@ -110,24 +106,24 @@ declare class CanceledError<T> extends AxiosError<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
declare class Axios {
|
declare class Axios {
|
||||||
constructor(config?: axios.RawAxiosRequestConfig);
|
constructor(config?: axios.AxiosRequestConfig);
|
||||||
defaults: axios.AxiosDefaults;
|
defaults: axios.AxiosDefaults;
|
||||||
interceptors: {
|
interceptors: {
|
||||||
request: axios.AxiosInterceptorManager<axios.AxiosRequestConfig>;
|
request: axios.AxiosInterceptorManager<axios.InternalAxiosRequestConfig>;
|
||||||
response: axios.AxiosInterceptorManager<axios.AxiosResponse>;
|
response: axios.AxiosInterceptorManager<axios.AxiosResponse>;
|
||||||
};
|
};
|
||||||
getUri(config?: axios.RawAxiosRequestConfig): string;
|
getUri(config?: axios.AxiosRequestConfig): string;
|
||||||
request<T = any, R = axios.AxiosResponse<T>, D = any>(config: axios.RawAxiosRequestConfig<D>): Promise<R>;
|
request<T = any, R = axios.AxiosResponse<T>, D = any>(config: axios.AxiosRequestConfig<D>): Promise<R>;
|
||||||
get<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.RawAxiosRequestConfig<D>): Promise<R>;
|
get<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
||||||
delete<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.RawAxiosRequestConfig<D>): Promise<R>;
|
delete<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
||||||
head<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.RawAxiosRequestConfig<D>): Promise<R>;
|
head<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
||||||
options<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.RawAxiosRequestConfig<D>): Promise<R>;
|
options<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
||||||
post<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.RawAxiosRequestConfig<D>): Promise<R>;
|
post<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
||||||
put<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.RawAxiosRequestConfig<D>): Promise<R>;
|
put<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
||||||
patch<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.RawAxiosRequestConfig<D>): Promise<R>;
|
patch<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
||||||
postForm<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.RawAxiosRequestConfig<D>): Promise<R>;
|
postForm<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
||||||
putForm<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.RawAxiosRequestConfig<D>): Promise<R>;
|
putForm<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
||||||
patchForm<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.RawAxiosRequestConfig<D>): Promise<R>;
|
patchForm<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare enum HttpStatusCode {
|
declare enum HttpStatusCode {
|
||||||
@@ -203,30 +199,34 @@ declare namespace axios {
|
|||||||
|
|
||||||
type CommonRequestHeadersList = 'Accept' | 'Content-Type' | 'Content-Length' | 'User-Agent'| 'Content-Encoding';
|
type CommonRequestHeadersList = 'Accept' | 'Content-Type' | 'Content-Length' | 'User-Agent'| 'Content-Encoding';
|
||||||
|
|
||||||
type RawCommonRequestHeaders = {
|
type RawAxiosRequestHeaders = Partial<RawAxiosHeaders & {
|
||||||
[Key in CommonRequestHeadersList]: AxiosHeaderValue;
|
[Key in CommonRequestHeadersList]: AxiosHeaderValue;
|
||||||
|
}>;
|
||||||
|
|
||||||
|
type AxiosRequestHeaders = RawAxiosRequestHeaders & AxiosHeaders;
|
||||||
|
|
||||||
|
type CommonResponseHeadersList = 'Server' | 'Content-Type' | 'Content-Length' | 'Cache-Control'| 'Content-Encoding';
|
||||||
|
|
||||||
|
type RawCommonResponseHeaders = {
|
||||||
|
[Key in CommonResponseHeadersList]: AxiosHeaderValue;
|
||||||
|
} & {
|
||||||
|
"set-cookie": string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
type RawAxiosRequestHeaders = Partial<RawAxiosHeaders & MethodsHeaders & CommonHeaders>;
|
type RawAxiosResponseHeaders = Partial<RawAxiosHeaders & RawCommonResponseHeaders>;
|
||||||
|
|
||||||
type AxiosRequestHeaders = Partial<RawCommonRequestHeaders & RawAxiosHeaders> & AxiosHeaders;
|
|
||||||
|
|
||||||
type RawAxiosResponseHeaders = Partial<Record<string, string> & {
|
|
||||||
"set-cookie"?: string[]
|
|
||||||
}>;
|
|
||||||
|
|
||||||
type AxiosResponseHeaders = RawAxiosResponseHeaders & AxiosHeaders;
|
type AxiosResponseHeaders = RawAxiosResponseHeaders & AxiosHeaders;
|
||||||
|
|
||||||
interface AxiosRequestTransformer {
|
interface AxiosRequestTransformer {
|
||||||
(this: AxiosRequestConfig, data: any, headers: AxiosRequestHeaders): any;
|
(this: InternalAxiosRequestConfig, data: any, headers: AxiosRequestHeaders): any;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AxiosResponseTransformer {
|
interface AxiosResponseTransformer {
|
||||||
(this: AxiosRequestConfig, data: any, headers: AxiosResponseHeaders, status?: number): any;
|
(this: InternalAxiosRequestConfig, data: any, headers: AxiosResponseHeaders, status?: number): any;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AxiosAdapter {
|
interface AxiosAdapter {
|
||||||
(config: AxiosRequestConfig): AxiosPromise;
|
(config: InternalAxiosRequestConfig): AxiosPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AxiosBasicCredentials {
|
interface AxiosBasicCredentials {
|
||||||
@@ -355,13 +355,13 @@ declare namespace axios {
|
|||||||
|
|
||||||
type AxiosAdapterConfig = AxiosAdapter | AxiosAdapterName;
|
type AxiosAdapterConfig = AxiosAdapter | AxiosAdapterName;
|
||||||
|
|
||||||
interface RawAxiosRequestConfig<D = any> {
|
interface AxiosRequestConfig<D = any> {
|
||||||
url?: string;
|
url?: string;
|
||||||
method?: Method | string;
|
method?: Method | string;
|
||||||
baseURL?: string;
|
baseURL?: string;
|
||||||
transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
|
transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
|
||||||
transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
|
transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
|
||||||
headers?: RawAxiosRequestHeaders | AxiosHeaders;
|
headers?: (RawAxiosRequestHeaders & MethodsHeaders) | AxiosHeaders;
|
||||||
params?: any;
|
params?: any;
|
||||||
paramsSerializer?: ParamsSerializerOptions;
|
paramsSerializer?: ParamsSerializerOptions;
|
||||||
data?: D;
|
data?: D;
|
||||||
@@ -397,7 +397,10 @@ declare namespace axios {
|
|||||||
formSerializer?: FormSerializerOptions;
|
formSerializer?: FormSerializerOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AxiosRequestConfig<D = any> extends RawAxiosRequestConfig {
|
// Alias
|
||||||
|
type RawAxiosRequestConfig<D = any> = AxiosRequestConfig<D>;
|
||||||
|
|
||||||
|
interface InternalAxiosRequestConfig<D = any> extends AxiosRequestConfig {
|
||||||
headers: AxiosRequestHeaders;
|
headers: AxiosRequestHeaders;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -415,11 +418,11 @@ declare namespace axios {
|
|||||||
unlink?: RawAxiosRequestHeaders;
|
unlink?: RawAxiosRequestHeaders;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AxiosDefaults<D = any> extends Omit<RawAxiosRequestConfig<D>, 'headers'> {
|
interface AxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
|
||||||
headers: HeadersDefaults;
|
headers: HeadersDefaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CreateAxiosDefaults<D = any> extends Omit<RawAxiosRequestConfig<D>, 'headers'> {
|
interface CreateAxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
|
||||||
headers?: RawAxiosRequestHeaders | AxiosHeaders | Partial<HeadersDefaults>;
|
headers?: RawAxiosRequestHeaders | AxiosHeaders | Partial<HeadersDefaults>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,7 +431,7 @@ declare namespace axios {
|
|||||||
status: number;
|
status: number;
|
||||||
statusText: string;
|
statusText: string;
|
||||||
headers: RawAxiosResponseHeaders | AxiosResponseHeaders;
|
headers: RawAxiosResponseHeaders | AxiosResponseHeaders;
|
||||||
config: AxiosRequestConfig<D>;
|
config: InternalAxiosRequestConfig<D>;
|
||||||
request?: any;
|
request?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -443,7 +446,7 @@ declare namespace axios {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface Canceler {
|
interface Canceler {
|
||||||
(message?: string, config?: RawAxiosRequestConfig, request?: any): void;
|
(message?: string, config?: AxiosRequestConfig, request?: any): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CancelTokenStatic {
|
interface CancelTokenStatic {
|
||||||
@@ -464,7 +467,7 @@ declare namespace axios {
|
|||||||
|
|
||||||
interface AxiosInterceptorOptions {
|
interface AxiosInterceptorOptions {
|
||||||
synchronous?: boolean;
|
synchronous?: boolean;
|
||||||
runWhen?: (config: AxiosRequestConfig) => boolean;
|
runWhen?: (config: InternalAxiosRequestConfig) => boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AxiosInterceptorManager<V> {
|
interface AxiosInterceptorManager<V> {
|
||||||
@@ -474,8 +477,8 @@ declare namespace axios {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface AxiosInstance extends Axios {
|
interface AxiosInstance extends Axios {
|
||||||
<T = any, R = AxiosResponse<T>, D = any>(config: RawAxiosRequestConfig<D>): Promise<R>;
|
<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
|
||||||
<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: RawAxiosRequestConfig<D>): Promise<R>;
|
<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
||||||
|
|
||||||
defaults: Omit<AxiosDefaults, 'headers'> & {
|
defaults: Omit<AxiosDefaults, 'headers'> & {
|
||||||
headers: HeadersDefaults & {
|
headers: HeadersDefaults & {
|
||||||
|
|||||||
Vendored
+47
-44
@@ -5,13 +5,9 @@ interface RawAxiosHeaders {
|
|||||||
[key: string]: AxiosHeaderValue;
|
[key: string]: AxiosHeaderValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
type MethodsHeaders = {
|
type MethodsHeaders = Partial<{
|
||||||
[Key in Method as Lowercase<Key>]: AxiosHeaders;
|
[Key in Method as Lowercase<Key>]: AxiosHeaders;
|
||||||
};
|
} & {common: AxiosHeaders}>;
|
||||||
|
|
||||||
interface CommonHeaders {
|
|
||||||
common: AxiosHeaders;
|
|
||||||
}
|
|
||||||
|
|
||||||
type AxiosHeaderMatcher = (this: AxiosHeaders, value: string, name: string, headers: RawAxiosHeaders) => boolean;
|
type AxiosHeaderMatcher = (this: AxiosHeaders, value: string, name: string, headers: RawAxiosHeaders) => boolean;
|
||||||
|
|
||||||
@@ -78,30 +74,34 @@ export class AxiosHeaders {
|
|||||||
|
|
||||||
type CommonRequestHeadersList = 'Accept' | 'Content-Type' | 'Content-Length' | 'User-Agent'| 'Content-Encoding';
|
type CommonRequestHeadersList = 'Accept' | 'Content-Type' | 'Content-Length' | 'User-Agent'| 'Content-Encoding';
|
||||||
|
|
||||||
type RawCommonRequestHeaders = {
|
export type RawAxiosRequestHeaders = Partial<RawAxiosHeaders & {
|
||||||
[Key in CommonRequestHeadersList]: AxiosHeaderValue;
|
[Key in CommonRequestHeadersList]: AxiosHeaderValue;
|
||||||
|
}>;
|
||||||
|
|
||||||
|
export type AxiosRequestHeaders = RawAxiosRequestHeaders & AxiosHeaders;
|
||||||
|
|
||||||
|
type CommonResponseHeadersList = 'Server' | 'Content-Type' | 'Content-Length' | 'Cache-Control'| 'Content-Encoding';
|
||||||
|
|
||||||
|
type RawCommonResponseHeaders = {
|
||||||
|
[Key in CommonResponseHeadersList]: AxiosHeaderValue;
|
||||||
|
} & {
|
||||||
|
"set-cookie": string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type RawAxiosRequestHeaders = Partial<RawAxiosHeaders & MethodsHeaders & CommonHeaders>;
|
export type RawAxiosResponseHeaders = Partial<RawAxiosHeaders & RawCommonResponseHeaders>;
|
||||||
|
|
||||||
export type AxiosRequestHeaders = Partial<RawCommonRequestHeaders & RawAxiosHeaders> & AxiosHeaders;
|
|
||||||
|
|
||||||
export type RawAxiosResponseHeaders = Partial<Record<string, string> & {
|
|
||||||
"set-cookie"?: string[]
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export type AxiosResponseHeaders = RawAxiosResponseHeaders & AxiosHeaders;
|
export type AxiosResponseHeaders = RawAxiosResponseHeaders & AxiosHeaders;
|
||||||
|
|
||||||
export interface AxiosRequestTransformer {
|
export interface AxiosRequestTransformer {
|
||||||
(this: AxiosRequestConfig, data: any, headers: AxiosRequestHeaders): any;
|
(this: InternalAxiosRequestConfig, data: any, headers: AxiosRequestHeaders): any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AxiosResponseTransformer {
|
export interface AxiosResponseTransformer {
|
||||||
(this: AxiosRequestConfig, data: any, headers: AxiosResponseHeaders, status?: number): any;
|
(this: InternalAxiosRequestConfig, data: any, headers: AxiosResponseHeaders, status?: number): any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AxiosAdapter {
|
export interface AxiosAdapter {
|
||||||
(config: AxiosRequestConfig): AxiosPromise;
|
(config: InternalAxiosRequestConfig): AxiosPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AxiosBasicCredentials {
|
export interface AxiosBasicCredentials {
|
||||||
@@ -296,13 +296,13 @@ type AxiosAdapterName = 'xhr' | 'http' | string;
|
|||||||
|
|
||||||
type AxiosAdapterConfig = AxiosAdapter | AxiosAdapterName;
|
type AxiosAdapterConfig = AxiosAdapter | AxiosAdapterName;
|
||||||
|
|
||||||
export interface RawAxiosRequestConfig<D = any> {
|
export interface AxiosRequestConfig<D = any> {
|
||||||
url?: string;
|
url?: string;
|
||||||
method?: Method | string;
|
method?: Method | string;
|
||||||
baseURL?: string;
|
baseURL?: string;
|
||||||
transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
|
transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
|
||||||
transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
|
transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
|
||||||
headers?: RawAxiosRequestHeaders | AxiosHeaders;
|
headers?: (RawAxiosRequestHeaders & MethodsHeaders) | AxiosHeaders;
|
||||||
params?: any;
|
params?: any;
|
||||||
paramsSerializer?: ParamsSerializerOptions;
|
paramsSerializer?: ParamsSerializerOptions;
|
||||||
data?: D;
|
data?: D;
|
||||||
@@ -338,7 +338,10 @@ export interface RawAxiosRequestConfig<D = any> {
|
|||||||
formSerializer?: FormSerializerOptions;
|
formSerializer?: FormSerializerOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AxiosRequestConfig<D = any> extends RawAxiosRequestConfig<D> {
|
// Alias
|
||||||
|
export type RawAxiosRequestConfig<D = any> = AxiosRequestConfig<D>;
|
||||||
|
|
||||||
|
export interface InternalAxiosRequestConfig<D = any> extends AxiosRequestConfig<D> {
|
||||||
headers: AxiosRequestHeaders;
|
headers: AxiosRequestHeaders;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,11 +359,11 @@ export interface HeadersDefaults {
|
|||||||
unlink?: RawAxiosRequestHeaders;
|
unlink?: RawAxiosRequestHeaders;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AxiosDefaults<D = any> extends Omit<RawAxiosRequestConfig<D>, 'headers'> {
|
export interface AxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
|
||||||
headers: HeadersDefaults;
|
headers: HeadersDefaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CreateAxiosDefaults<D = any> extends Omit<RawAxiosRequestConfig<D>, 'headers'> {
|
export interface CreateAxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
|
||||||
headers?: RawAxiosRequestHeaders | AxiosHeaders | Partial<HeadersDefaults>;
|
headers?: RawAxiosRequestHeaders | AxiosHeaders | Partial<HeadersDefaults>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,7 +372,7 @@ export interface AxiosResponse<T = any, D = any> {
|
|||||||
status: number;
|
status: number;
|
||||||
statusText: string;
|
statusText: string;
|
||||||
headers: RawAxiosResponseHeaders | AxiosResponseHeaders;
|
headers: RawAxiosResponseHeaders | AxiosResponseHeaders;
|
||||||
config: AxiosRequestConfig<D>;
|
config: InternalAxiosRequestConfig<D>;
|
||||||
request?: any;
|
request?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -377,12 +380,12 @@ export class AxiosError<T = unknown, D = any> extends Error {
|
|||||||
constructor(
|
constructor(
|
||||||
message?: string,
|
message?: string,
|
||||||
code?: string,
|
code?: string,
|
||||||
config?: AxiosRequestConfig<D>,
|
config?: InternalAxiosRequestConfig<D>,
|
||||||
request?: any,
|
request?: any,
|
||||||
response?: AxiosResponse<T, D>
|
response?: AxiosResponse<T, D>
|
||||||
);
|
);
|
||||||
|
|
||||||
config?: AxiosRequestConfig<D>;
|
config?: InternalAxiosRequestConfig<D>;
|
||||||
code?: string;
|
code?: string;
|
||||||
request?: any;
|
request?: any;
|
||||||
response?: AxiosResponse<T, D>;
|
response?: AxiosResponse<T, D>;
|
||||||
@@ -393,7 +396,7 @@ export class AxiosError<T = unknown, D = any> extends Error {
|
|||||||
static from<T = unknown, D = any>(
|
static from<T = unknown, D = any>(
|
||||||
error: Error | unknown,
|
error: Error | unknown,
|
||||||
code?: string,
|
code?: string,
|
||||||
config?: AxiosRequestConfig<D>,
|
config?: InternalAxiosRequestConfig<D>,
|
||||||
request?: any,
|
request?: any,
|
||||||
response?: AxiosResponse<T, D>,
|
response?: AxiosResponse<T, D>,
|
||||||
customProps?: object,
|
customProps?: object,
|
||||||
@@ -426,7 +429,7 @@ export interface Cancel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Canceler {
|
export interface Canceler {
|
||||||
(message?: string, config?: RawAxiosRequestConfig, request?: any): void;
|
(message?: string, config?: AxiosRequestConfig, request?: any): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CancelTokenStatic {
|
export interface CancelTokenStatic {
|
||||||
@@ -447,7 +450,7 @@ export interface CancelTokenSource {
|
|||||||
|
|
||||||
export interface AxiosInterceptorOptions {
|
export interface AxiosInterceptorOptions {
|
||||||
synchronous?: boolean;
|
synchronous?: boolean;
|
||||||
runWhen?: (config: AxiosRequestConfig) => boolean;
|
runWhen?: (config: InternalAxiosRequestConfig) => boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AxiosInterceptorManager<V> {
|
export interface AxiosInterceptorManager<V> {
|
||||||
@@ -457,29 +460,29 @@ export interface AxiosInterceptorManager<V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Axios {
|
export class Axios {
|
||||||
constructor(config?: RawAxiosRequestConfig);
|
constructor(config?: AxiosRequestConfig);
|
||||||
defaults: AxiosDefaults;
|
defaults: AxiosDefaults;
|
||||||
interceptors: {
|
interceptors: {
|
||||||
request: AxiosInterceptorManager<AxiosRequestConfig>;
|
request: AxiosInterceptorManager<InternalAxiosRequestConfig>;
|
||||||
response: AxiosInterceptorManager<AxiosResponse>;
|
response: AxiosInterceptorManager<AxiosResponse>;
|
||||||
};
|
};
|
||||||
getUri(config?: RawAxiosRequestConfig): string;
|
getUri(config?: AxiosRequestConfig): string;
|
||||||
request<T = any, R = AxiosResponse<T>, D = any>(config: RawAxiosRequestConfig<D>): Promise<R>;
|
request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
|
||||||
get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: RawAxiosRequestConfig<D>): Promise<R>;
|
get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
||||||
delete<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: RawAxiosRequestConfig<D>): Promise<R>;
|
delete<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
||||||
head<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: RawAxiosRequestConfig<D>): Promise<R>;
|
head<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
||||||
options<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: RawAxiosRequestConfig<D>): Promise<R>;
|
options<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
||||||
post<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: RawAxiosRequestConfig<D>): Promise<R>;
|
post<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
||||||
put<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: RawAxiosRequestConfig<D>): Promise<R>;
|
put<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
||||||
patch<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: RawAxiosRequestConfig<D>): Promise<R>;
|
patch<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
||||||
postForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: RawAxiosRequestConfig<D>): Promise<R>;
|
postForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
||||||
putForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: RawAxiosRequestConfig<D>): Promise<R>;
|
putForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
||||||
patchForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: RawAxiosRequestConfig<D>): Promise<R>;
|
patchForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AxiosInstance extends Axios {
|
export interface AxiosInstance extends Axios {
|
||||||
<T = any, R = AxiosResponse<T>, D = any>(config: RawAxiosRequestConfig<D>): Promise<R>;
|
<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
|
||||||
<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: RawAxiosRequestConfig<D>): Promise<R>;
|
<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
||||||
|
|
||||||
defaults: Omit<AxiosDefaults, 'headers'> & {
|
defaults: Omit<AxiosDefaults, 'headers'> & {
|
||||||
headers: HeadersDefaults & {
|
headers: HeadersDefaults & {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import axios = require('axios');
|
import axios = require('axios');
|
||||||
|
|
||||||
const config: axios.RawAxiosRequestConfig = {
|
const config: axios.AxiosRequestConfig = {
|
||||||
url: '/user',
|
url: '/user',
|
||||||
method: 'get',
|
method: 'get',
|
||||||
baseURL: 'https://api.example.com/',
|
baseURL: 'https://api.example.com/',
|
||||||
@@ -38,11 +38,11 @@ const config: axios.RawAxiosRequestConfig = {
|
|||||||
cancelToken: new axios.CancelToken((cancel: axios.Canceler) => {})
|
cancelToken: new axios.CancelToken((cancel: axios.Canceler) => {})
|
||||||
};
|
};
|
||||||
|
|
||||||
const nullValidateStatusConfig: axios.RawAxiosRequestConfig = {
|
const nullValidateStatusConfig: axios.AxiosRequestConfig = {
|
||||||
validateStatus: null
|
validateStatus: null
|
||||||
};
|
};
|
||||||
|
|
||||||
const undefinedValidateStatusConfig: axios.RawAxiosRequestConfig = {
|
const undefinedValidateStatusConfig: axios.AxiosRequestConfig = {
|
||||||
validateStatus: undefined
|
validateStatus: undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -276,19 +276,19 @@ axios.create({
|
|||||||
// Interceptors
|
// Interceptors
|
||||||
|
|
||||||
const requestInterceptorId: number = axios.interceptors.request.use(
|
const requestInterceptorId: number = axios.interceptors.request.use(
|
||||||
(config: axios.AxiosRequestConfig) => config,
|
(config: axios.InternalAxiosRequestConfig) => config,
|
||||||
(error: any) => Promise.reject(error)
|
(error: any) => Promise.reject(error)
|
||||||
);
|
);
|
||||||
|
|
||||||
axios.interceptors.request.eject(requestInterceptorId);
|
axios.interceptors.request.eject(requestInterceptorId);
|
||||||
|
|
||||||
axios.interceptors.request.use(
|
axios.interceptors.request.use(
|
||||||
(config: axios.AxiosRequestConfig) => Promise.resolve(config),
|
(config: axios.InternalAxiosRequestConfig) => Promise.resolve(config),
|
||||||
(error: any) => Promise.reject(error)
|
(error: any) => Promise.reject(error)
|
||||||
);
|
);
|
||||||
|
|
||||||
axios.interceptors.request.use((config: axios.AxiosRequestConfig) => config);
|
axios.interceptors.request.use((config: axios.InternalAxiosRequestConfig) => config);
|
||||||
axios.interceptors.request.use((config: axios.AxiosRequestConfig) => Promise.resolve(config));
|
axios.interceptors.request.use((config: axios.InternalAxiosRequestConfig) => Promise.resolve(config));
|
||||||
|
|
||||||
const responseInterceptorId: number = axios.interceptors.response.use(
|
const responseInterceptorId: number = axios.interceptors.response.use(
|
||||||
(response: axios.AxiosResponse) => response,
|
(response: axios.AxiosResponse) => response,
|
||||||
@@ -302,6 +302,13 @@ axios.interceptors.response.use(
|
|||||||
(error: any) => Promise.reject(error)
|
(error: any) => Promise.reject(error)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
axios.interceptors.request.use(req => {
|
||||||
|
// https://github.com/axios/axios/issues/5415
|
||||||
|
req.headers.set('foo', 'bar');
|
||||||
|
req.headers['Content-Type'] = 123;
|
||||||
|
return req;
|
||||||
|
});
|
||||||
|
|
||||||
const voidRequestInterceptorId = axios.interceptors.request.use(
|
const voidRequestInterceptorId = axios.interceptors.request.use(
|
||||||
// @ts-expect-error -- Must return an axios.AxiosRequestConfig (or throw)
|
// @ts-expect-error -- Must return an axios.AxiosRequestConfig (or throw)
|
||||||
(_response) => {},
|
(_response) => {},
|
||||||
@@ -323,7 +330,7 @@ axios.interceptors.response.clear();
|
|||||||
|
|
||||||
// Adapters
|
// Adapters
|
||||||
|
|
||||||
const adapter: axios.AxiosAdapter = (config: axios.AxiosRequestConfig) => {
|
const adapter: axios.AxiosAdapter = (config: axios.InternalAxiosRequestConfig) => {
|
||||||
const response: axios.AxiosResponse = {
|
const response: axios.AxiosResponse = {
|
||||||
data: { foo: 'bar' },
|
data: { foo: 'bar' },
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import axios, {
|
import axios, {
|
||||||
RawAxiosRequestConfig,
|
InternalAxiosRequestConfig,
|
||||||
AxiosRequestConfig,
|
AxiosRequestConfig,
|
||||||
AxiosHeaders,
|
AxiosHeaders,
|
||||||
AxiosRequestHeaders,
|
AxiosRequestHeaders,
|
||||||
@@ -22,7 +22,7 @@ import axios, {
|
|||||||
spread
|
spread
|
||||||
} from 'axios';
|
} from 'axios';
|
||||||
|
|
||||||
const config: RawAxiosRequestConfig = {
|
const config: AxiosRequestConfig = {
|
||||||
url: '/user',
|
url: '/user',
|
||||||
method: 'get',
|
method: 'get',
|
||||||
baseURL: 'https://api.example.com/',
|
baseURL: 'https://api.example.com/',
|
||||||
@@ -60,11 +60,11 @@ const config: RawAxiosRequestConfig = {
|
|||||||
cancelToken: new axios.CancelToken((cancel: Canceler) => {})
|
cancelToken: new axios.CancelToken((cancel: Canceler) => {})
|
||||||
};
|
};
|
||||||
|
|
||||||
const nullValidateStatusConfig: RawAxiosRequestConfig = {
|
const nullValidateStatusConfig: AxiosRequestConfig = {
|
||||||
validateStatus: null
|
validateStatus: null
|
||||||
};
|
};
|
||||||
|
|
||||||
const undefinedValidateStatusConfig: RawAxiosRequestConfig = {
|
const undefinedValidateStatusConfig: AxiosRequestConfig = {
|
||||||
validateStatus: undefined
|
validateStatus: undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -515,7 +515,7 @@ axios.get('/user', {
|
|||||||
|
|
||||||
// issue #5034
|
// issue #5034
|
||||||
|
|
||||||
function getRequestConfig1(options: RawAxiosRequestConfig): RawAxiosRequestConfig {
|
function getRequestConfig1(options: AxiosRequestConfig): AxiosRequestConfig {
|
||||||
return {
|
return {
|
||||||
...options,
|
...options,
|
||||||
headers: {
|
headers: {
|
||||||
@@ -525,7 +525,7 @@ function getRequestConfig1(options: RawAxiosRequestConfig): RawAxiosRequestConfi
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRequestConfig2(options: RawAxiosRequestConfig): RawAxiosRequestConfig {
|
function getRequestConfig2(options: AxiosRequestConfig): AxiosRequestConfig {
|
||||||
return {
|
return {
|
||||||
...options,
|
...options,
|
||||||
headers: {
|
headers: {
|
||||||
@@ -609,7 +609,7 @@ for (const [header, value] of headers) {
|
|||||||
config.headers.foo = "1";
|
config.headers.foo = "1";
|
||||||
config.headers.set('bar', '2');
|
config.headers.set('bar', '2');
|
||||||
config.headers.set({myHeader: "myValue"})
|
config.headers.set({myHeader: "myValue"})
|
||||||
config.headers = new axios.AxiosHeaders({myHeader: "myValue"});
|
config.headers = new AxiosHeaders({myHeader: "myValue"});
|
||||||
config.headers = {...config.headers} as AxiosRequestHeaders;
|
config.headers = {...config.headers} as AxiosRequestHeaders;
|
||||||
return config;
|
return config;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user