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
Revert "Improved type-safety for AxiosRequestConfig (#2995)" #4111
Conversation
This reverts commit 4eeb3b1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commit you're reverting here is already included in v0.21.4, which doesn't have the issue, so IMO the regression must have been introduced in a different commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commit you're reverting here is already included in v0.21.4, which doesn't have the issue, so IMO the regression must have been introduced in a different commit.
Sorry, my bad, It only looks like that commit was part of that release, but the v0.21.4
does actually not contain those changes, see: https://unpkg.com/axios@0.21.4/index.d.ts
PS: Is this inconsistency between NPM release and git tag a known issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having given this revert another thought, wouldn't it be sufficient to remove AxiosRequestConfig's
type parameter, instead of reverting the any
to never
change as well?
See #4116.
No. The problem isn’t that While it is possible to add better type safety, it’s a bit more complex than that. Simply reverting at least fixes usage of axios 0.22.0 with TypeScript. |
Hm, if it does indeed make sense to keep the AxiosRequestConfig generic type parameter (rather than dropping it), the two options I can see are:
Wouldn't one of these forward fixes make more sense than reverting back? PS: My rationale includes that releasing the full revert as a patch release would require the subsequent fixed type-safety improvement to be released in another minor release (due to the |
Option 2 is a step in the right direction, but since type parameters are ordered, introducing a new type parameter before an existing one is a breaking change. request<T = never, R = AxiosResponse<T, D>, D> (config: AxiosRequestConfig<D>): Promise<R>; Although I have my doubts if it’s even that useful. The real benefit isn’t that the input config is typed. In fact, it would be better to omit post<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: Omit<AxiosRequestConfig, 'method' | 'url' | 'data'>): Promise<R>; Putting it all together, it becomes something like: post<T = never, R = AxiosResponse<T, D>, D>(url: string, data?: any, config?: Omit<AxiosRequestConfig<T, D>, 'method' | 'url' | 'data'>): Promise<R>; The only benefit this has over accepting |
I didn't see the benefit at first, but I more and more think it is, especially when generating those data typings automatically from API definitions. |
Do we really need to pass the |
Okay, we cannot reference the The following would be ideal, but unfortunately a breaking change: -post<T = never, R = AxiosResponse<T>>(url: string, data?: T, config?: AxiosRequestConfig<T>): Promise<R>;
+post<T = never, D = any, R = AxiosResponse<T>>(url: string, data?: D, config?: Omit<AxiosRequestConfig<T, D>, 'method' | 'url' | 'data'>): Promise<R>; |
From what I can tell from @jasonsaayman 's response (#3002 (comment)):
it sounds like they're using "master" (which is the tagged branch) as the 1.0.0 code, with release branches for the 0.x line |
I created another PR to fix this. Please check if that's what you're looking for. |
Closing this in favor of #4133. |
@remcohaszing Any reason to prefer #4133 over #4116? |
Nope. I just picked the one that was getting most attention. |
This reverts commit 4eeb3b1.
The reverted commit assumed the request and response body have to be of the same type. This makes axios 0.22.0 unusable with TypeScript.
Refs #2995
Closes #4109