-
-
Notifications
You must be signed in to change notification settings - Fork 11.6k
POST call expected response body type also set to request body type #4132
Description
Describe the bug
When specifying an expected response.data type to the post method it also sets that expected type to the request body. Also, when not specifying a type, the type for the response.data gets inferred to be the same as the type of the request body. This leads to typescript errors in VS Code and during compile time when the response and request bodies in code doesn't have the same type (which is usually the case). This was not an issue in v0.21.4 - which I reverted to in order to get around this issue.
To Reproduce
- Install axios v0.22.0
- Add a type for the
response.datalike in this example:
axios.post<ExpectedResponseBody>(`post url`, { foo: "bar" }, {});Also look at the CodeSandbox example here
Expected behavior
When specifying the expected type of the response.data in the post call, the request body shouldn't have the same expected type. And the inferred type for the request body shouldn't automatically get applied to response.data.
Environment
- Axios Version 0.22.0
- Adapter N/A
- Browser N/A
- Browser Version N/A
- Node.js Version: 14.17.3
- OS: Win 10
- Additional Library Versions: Typescript 4.4.3
Additional context/Screenshots
Type for post method in axios v0.21.4

Type for post method in axios v0.22.0. Note that T is also set to request data and config in this version - which is what I believe is the cause of the issue.
