-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
POST call expected response body type also set to request body type #4132
Comments
Same problem here when updating to 0.22; it literally broke the whole app. |
Duplicate to #4109 |
Thank you. I couldn't find an existing issue for this when I started writing up my issue on Saturday. |
You're welcome. Axios team messed up with the last release. Maybe they deserve issue overflow 😶 |
Yeah it's frankly concerning how this got through. We all make mistakes but this is a big one to miss 🙃 It looks like their TypeScript tests may be incorrectly written? I'm not sure, and I don't really want to dig into it... but I'm not sure why the tests didn't catch this. axios/test/typescript/axios.ts Lines 200 to 202 in 76f09af
If I'm not mistaken, |
Your assumption on the type is incorrect. it should be |
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 theresponse.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
response.data
like in this example: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 toresponse.data
.Environment
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.The text was updated successfully, but these errors were encountered: