mirror of
https://github.com/tenrok/axios.git
synced 2026-06-17 19:21:29 +03:00
Improved type-safety for AxiosRequestConfig (#2995)
* Improved type-safety for AxiosRequestConfig - AxiosRequestConfig is now a generic type whose template corresponds to data Signed-off-by: Carlos Chida <carlos.chida@starchitecture.eu> * Fixed tests - TS tests now match the behaviour described in the PR Signed-off-by: Carlos Chida <carlos.chida@starchitecture.eu> Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
Vendored
+11
-11
@@ -47,7 +47,7 @@ export interface TransitionalOptions{
|
||||
clarifyTimeoutError: boolean;
|
||||
}
|
||||
|
||||
export interface AxiosRequestConfig {
|
||||
export interface AxiosRequestConfig<T = any> {
|
||||
url?: string;
|
||||
method?: Method;
|
||||
baseURL?: string;
|
||||
@@ -56,7 +56,7 @@ export interface AxiosRequestConfig {
|
||||
headers?: any;
|
||||
params?: any;
|
||||
paramsSerializer?: (params: any) => string;
|
||||
data?: any;
|
||||
data?: T;
|
||||
timeout?: number;
|
||||
timeoutErrorMessage?: string;
|
||||
withCredentials?: boolean;
|
||||
@@ -85,7 +85,7 @@ export interface AxiosResponse<T = any> {
|
||||
status: number;
|
||||
statusText: string;
|
||||
headers: any;
|
||||
config: AxiosRequestConfig;
|
||||
config: AxiosRequestConfig<T>;
|
||||
request?: any;
|
||||
}
|
||||
|
||||
@@ -142,14 +142,14 @@ export class Axios {
|
||||
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>;
|
||||
request<T = any, R = AxiosResponse<T>> (config: AxiosRequestConfig<T>): Promise<R>;
|
||||
get<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig<T>): Promise<R>;
|
||||
delete<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig<T>): Promise<R>;
|
||||
head<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig<T>): Promise<R>;
|
||||
options<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig<T>): Promise<R>;
|
||||
post<T = any, R = AxiosResponse<T>>(url: string, data?: T, config?: AxiosRequestConfig<T>): Promise<R>;
|
||||
put<T = any, R = AxiosResponse<T>>(url: string, data?: T, config?: AxiosRequestConfig<T>): Promise<R>;
|
||||
patch<T = any, R = AxiosResponse<T>>(url: string, data?: T, config?: AxiosRequestConfig<T>): Promise<R>;
|
||||
}
|
||||
|
||||
export interface AxiosInstance extends Axios {
|
||||
|
||||
Reference in New Issue
Block a user