Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify generic usage on method types #4313

Closed
Retro64 opened this issue Dec 6, 2021 · 2 comments
Closed

Simplify generic usage on method types #4313

Retro64 opened this issue Dec 6, 2021 · 2 comments

Comments

@Retro64
Copy link

Retro64 commented Dec 6, 2021

Is your feature request related to a problem? Please describe.

Currently, the types describing the methods are using three parameters (see https://github.com/axios/axios/blob/master/index.d.ts#L177)

get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;

At least from my point of view, the second parameter does not bring in any additional value, as it is not really configurable, but simply relies on the first parameter.

Describe the solution you'd like

Bringing in the AxiosResponse to the return type, would end in a cleaner interface, only defined by input and returned type (in fact type of Promise of AxiosResponse):

get<T = any, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<AxiosResponse<T>>;

Describe alternatives you've considered

For sure, the type can be kept this way, but brings in some mental overhead and no benefit in defining the second generic parameter.

Additional context

I know this might be a breaking change, but I guess it brings in more clarity on the interface, simply dependent from input and output types.

@Retro64
Copy link
Author

Retro64 commented Dec 6, 2021

Addition:

from my point of view, even

get<T, D>(url: string, config?: AxiosRequestConfig<D>): Promise<AxiosResponse<T>>;

should work out and resolve #4141 and the root cause of #4142 , as the type should be inferred by the compiler (see last passages of https://www.typescriptlang.org/docs/handbook/2/generics.html#hello-world-of-generics ).

@Retro64 Retro64 closed this as completed Dec 7, 2021
@dietergeerts
Copy link

Why is this closed? Will this be considered in future releases, or will this just not be implemented? Currently, to type the body, we need to add the second type param each time, which should not be needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants