Skip to content

Commit

Permalink
Revert "Improved type-safety for AxiosRequestConfig (axios#2995)"
Browse files Browse the repository at this point in the history
This reverts commit 4eeb3b1.
  • Loading branch information
remcohaszing committed Oct 1, 2021
1 parent 76f09af commit 46abbcd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
22 changes: 11 additions & 11 deletions index.d.ts
Expand Up @@ -47,7 +47,7 @@ export interface TransitionalOptions{
clarifyTimeoutError: boolean;
}

export interface AxiosRequestConfig<T = any> {
export interface AxiosRequestConfig {
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?: any;
timeout?: number;
timeoutErrorMessage?: string;
withCredentials?: boolean;
Expand Down Expand Up @@ -86,7 +86,7 @@ export interface AxiosResponse<T = never> {
status: number;
statusText: string;
headers: Record<string, string>;
config: AxiosRequestConfig<T>;
config: AxiosRequestConfig;
request?: any;
}

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 = 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 AxiosInstance extends Axios {
Expand Down
22 changes: 9 additions & 13 deletions test/typescript/axios.ts
Expand Up @@ -111,10 +111,6 @@ axios.patch('/user', { foo: 'bar' })
.catch(handleError);

// Typed methods
interface UserCreationDef {
name: string;
}

interface User {
id: number;
name: string;
Expand Down Expand Up @@ -142,7 +138,7 @@ axios.get<User>('/user', { params: { id: 12345 } })
axios.head<User>('/user')
.then(handleUserResponse)
.catch(handleError);

axios.options<User>('/user')
.then(handleUserResponse)
.catch(handleError);
Expand All @@ -151,19 +147,19 @@ axios.delete<User>('/user')
.then(handleUserResponse)
.catch(handleError);

axios.post<User>('/user', { name: 'foo', id: 1 })
axios.post<User>('/user', { foo: 'bar' })
.then(handleUserResponse)
.catch(handleError);

axios.post<User>('/user', { name: 'foo', id: 1 }, { headers: { 'X-FOO': 'bar' } })
axios.post<User>('/user', { foo: 'bar' }, { headers: { 'X-FOO': 'bar' } })
.then(handleUserResponse)
.catch(handleError);

axios.put<User>('/user', { name: 'foo', id: 1 })
axios.put<User>('/user', { foo: 'bar' })
.then(handleUserResponse)
.catch(handleError);

axios.patch<User>('/user', { name: 'foo', id: 1 })
axios.patch<User>('/user', { foo: 'bar' })
.then(handleUserResponse)
.catch(handleError);

Expand Down Expand Up @@ -193,19 +189,19 @@ axios.delete<User, string>('/user')
.then(handleStringResponse)
.catch(handleError);

axios.post<Partial<UserCreationDef>, string>('/user', { name: 'foo' })
axios.post<User, string>('/user', { foo: 'bar' })
.then(handleStringResponse)
.catch(handleError);

axios.post<Partial<UserCreationDef>, string>('/user', { name: 'foo' }, { headers: { 'X-FOO': 'bar' } })
axios.post<User, string>('/user', { foo: 'bar' }, { headers: { 'X-FOO': 'bar' } })
.then(handleStringResponse)
.catch(handleError);

axios.put<Partial<UserCreationDef>, string>('/user', { name: 'foo' })
axios.put<User, string>('/user', { foo: 'bar' })
.then(handleStringResponse)
.catch(handleError);

axios.patch<Partial<UserCreationDef>, string>('/user', { name: 'foo' })
axios.patch<User, string>('/user', { foo: 'bar' })
.then(handleStringResponse)
.catch(handleError);

Expand Down

0 comments on commit 46abbcd

Please sign in to comment.