Skip to content

Commit

Permalink
Distinguish request and response data types (#4116)
Browse files Browse the repository at this point in the history
Co-authored-by: Jay <jasonsaayman@gmail.com>
  • Loading branch information
caugner and jasonsaayman committed Oct 6, 2021
1 parent ba9c193 commit 28a06e6
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export interface TransitionalOptions{
clarifyTimeoutError: boolean;
}

export interface AxiosRequestConfig<T = any> {
export interface AxiosRequestConfig<D = any> {
url?: string;
method?: Method;
baseURL?: string;
Expand All @@ -56,7 +56,7 @@ export interface AxiosRequestConfig<T = any> {
headers?: Record<string, string>;
params?: any;
paramsSerializer?: (params: any) => string;
data?: T;
data?: D;
timeout?: number;
timeoutErrorMessage?: string;
withCredentials?: boolean;
Expand All @@ -81,20 +81,20 @@ export interface AxiosRequestConfig<T = any> {
signal?: AbortSignal;
}

export interface AxiosResponse<T = never> {
export interface AxiosResponse<T = never, D = any> {
data: T;
status: number;
statusText: string;
headers: Record<string, string>;
config: AxiosRequestConfig<T>;
config: AxiosRequestConfig<D>;
request?: any;
}

export interface AxiosError<T = never> extends Error {
config: AxiosRequestConfig;
export interface AxiosError<T = never, D = any> extends Error {
config: AxiosRequestConfig<D>;
code?: string;
request?: any;
response?: AxiosResponse<T>;
response?: AxiosResponse<T, D>;
isAxiosError: boolean;
toJSON: () => object;
}
Expand Down Expand Up @@ -143,14 +143,14 @@ export class Axios {
response: AxiosInterceptorManager<AxiosResponse>;
};
getUri(config?: AxiosRequestConfig): string;
request<T = never, R = AxiosResponse<T>> (config: AxiosRequestConfig<T>): Promise<R>;
get<T = never, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig<T>): Promise<R>;
delete<T = never, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig<T>): Promise<R>;
head<T = never, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig<T>): Promise<R>;
options<T = never, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig<T>): Promise<R>;
post<T = never, R = AxiosResponse<T>>(url: string, data?: T, config?: AxiosRequestConfig<T>): Promise<R>;
put<T = never, R = AxiosResponse<T>>(url: string, data?: T, config?: AxiosRequestConfig<T>): Promise<R>;
patch<T = never, R = AxiosResponse<T>>(url: string, data?: T, config?: AxiosRequestConfig<T>): Promise<R>;
request<T = never, R = AxiosResponse<T>, D = any> (config: AxiosRequestConfig<D>): Promise<R>;
get<T = never, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
delete<T = never, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
head<T = never, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
options<T = never, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
post<T = never, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
put<T = never, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
patch<T = never, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
}

export interface AxiosInstance extends Axios {
Expand Down

0 comments on commit 28a06e6

Please sign in to comment.