Skip to content

Commit

Permalink
fix(types): renamed AxiosRequestConfig to `InternalAxiosRequestConf…
Browse files Browse the repository at this point in the history
…ig`;

renamed `RawAxiosRequestConfig` back to `AxiosRequestConfig`;
add `RawAxiosRequestConfig` as an alias of `AxiosRequestConfig`;
  • Loading branch information
DigitalBrainJS committed Jan 21, 2023
1 parent 54e6282 commit a5c78a2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 30 deletions.
61 changes: 32 additions & 29 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ export type RawAxiosResponseHeaders = Partial<Record<string, string> & {
export type AxiosResponseHeaders = RawAxiosResponseHeaders & AxiosHeaders;

export interface AxiosRequestTransformer {
(this: AxiosRequestConfig, data: any, headers: AxiosRequestHeaders): any;
(this: InternalAxiosRequestConfig, data: any, headers: AxiosRequestHeaders): any;
}

export interface AxiosResponseTransformer {
(this: AxiosRequestConfig, data: any, headers: AxiosResponseHeaders, status?: number): any;
(this: InternalAxiosRequestConfig, data: any, headers: AxiosResponseHeaders, status?: number): any;
}

export interface AxiosAdapter {
(config: AxiosRequestConfig): AxiosPromise;
(config: InternalAxiosRequestConfig): AxiosPromise;
}

export interface AxiosBasicCredentials {
Expand Down Expand Up @@ -296,7 +296,7 @@ type AxiosAdapterName = 'xhr' | 'http' | string;

type AxiosAdapterConfig = AxiosAdapter | AxiosAdapterName;

export interface RawAxiosRequestConfig<D = any> {
export interface AxiosRequestConfig<D = any> {
url?: string;
method?: Method | string;
baseURL?: string;
Expand Down Expand Up @@ -338,7 +338,10 @@ export interface RawAxiosRequestConfig<D = any> {
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;
}

Expand All @@ -356,11 +359,11 @@ export interface HeadersDefaults {
unlink?: RawAxiosRequestHeaders;
}

export interface AxiosDefaults<D = any> extends Omit<RawAxiosRequestConfig<D>, 'headers'> {
export interface AxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
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>;
}

Expand All @@ -369,20 +372,20 @@ export interface AxiosResponse<T = any, D = any> {
status: number;
statusText: string;
headers: RawAxiosResponseHeaders | AxiosResponseHeaders;
config: AxiosRequestConfig<D>;
config: InternalAxiosRequestConfig<D>;
request?: any;
}

export class AxiosError<T = unknown, D = any> extends Error {
constructor(
message?: string,
code?: string,
config?: AxiosRequestConfig<D>,
config?: InternalAxiosRequestConfig<D>,
request?: any,
response?: AxiosResponse<T, D>
);

config?: AxiosRequestConfig<D>;
config?: InternalAxiosRequestConfig<D>;
code?: string;
request?: any;
response?: AxiosResponse<T, D>;
Expand All @@ -393,7 +396,7 @@ export class AxiosError<T = unknown, D = any> extends Error {
static from<T = unknown, D = any>(
error: Error | unknown,
code?: string,
config?: AxiosRequestConfig<D>,
config?: InternalAxiosRequestConfig<D>,
request?: any,
response?: AxiosResponse<T, D>,
customProps?: object,
Expand Down Expand Up @@ -426,7 +429,7 @@ export interface Cancel {
}

export interface Canceler {
(message?: string, config?: RawAxiosRequestConfig, request?: any): void;
(message?: string, config?: AxiosRequestConfig, request?: any): void;
}

export interface CancelTokenStatic {
Expand All @@ -447,7 +450,7 @@ export interface CancelTokenSource {

export interface AxiosInterceptorOptions {
synchronous?: boolean;
runWhen?: (config: AxiosRequestConfig) => boolean;
runWhen?: (config: InternalAxiosRequestConfig) => boolean;
}

export interface AxiosInterceptorManager<V> {
Expand All @@ -457,29 +460,29 @@ export interface AxiosInterceptorManager<V> {
}

export class Axios {
constructor(config?: RawAxiosRequestConfig);
constructor(config?: AxiosRequestConfig);
defaults: AxiosDefaults;
interceptors: {
request: AxiosInterceptorManager<AxiosRequestConfig>;
request: AxiosInterceptorManager<InternalAxiosRequestConfig>;
response: AxiosInterceptorManager<AxiosResponse>;
};
getUri(config?: RawAxiosRequestConfig): string;
request<T = any, R = AxiosResponse<T>, D = any>(config: RawAxiosRequestConfig<D>): Promise<R>;
get<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?: RawAxiosRequestConfig<D>): Promise<R>;
head<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?: RawAxiosRequestConfig<D>): Promise<R>;
post<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?: RawAxiosRequestConfig<D>): Promise<R>;
patch<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?: RawAxiosRequestConfig<D>): Promise<R>;
putForm<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?: RawAxiosRequestConfig<D>): Promise<R>;
getUri(config?: AxiosRequestConfig): string;
request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<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?: AxiosRequestConfig<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?: AxiosRequestConfig<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?: AxiosRequestConfig<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?: AxiosRequestConfig<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?: AxiosRequestConfig<D>): Promise<R>;
}

export interface AxiosInstance extends Axios {
<T = any, R = AxiosResponse<T>, D = any>(config: RawAxiosRequestConfig<D>): Promise<R>;
<T = any, R = AxiosResponse<T>, D = any>(url: string, 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?: AxiosRequestConfig<D>): Promise<R>;

defaults: Omit<AxiosDefaults, 'headers'> & {
headers: HeadersDefaults & {
Expand Down
2 changes: 1 addition & 1 deletion test/module/typings/esm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ for (const [header, value] of headers) {
config.headers.foo = "1";
config.headers.set('bar', '2');
config.headers.set({myHeader: "myValue"})
config.headers = new axios.AxiosHeaders({myHeader: "myValue"});
config.headers = new AxiosHeaders({myHeader: "myValue"});
config.headers = {...config.headers} as AxiosRequestHeaders;
return config;
},
Expand Down

0 comments on commit a5c78a2

Please sign in to comment.