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

Unexpected type #4150

Closed
roj1512 opened this issue Oct 6, 2021 · 8 comments
Closed

Unexpected type #4150

roj1512 opened this issue Oct 6, 2021 · 8 comments

Comments

@roj1512
Copy link

roj1512 commented Oct 6, 2021

Describe the issue

The type of the .data of the response is the same type of what was submitted in the request.

Example Code

const form: FormData = new FormData();

const { data } = await axiosInstance.request({data: form});

// The type of data is `FormData`, why? It should be any or something else. The response is never FormData.

Expected behavior, if applicable

Type of data in the response should be any or something else.

Environment

  • Axios Version: 0.22.0
  • Adapter: HTTP
  • Browser: N/A
  • Browser Version: N/A
  • Node.js Version: 16.9.1
  • TypeScript Version: 4.4.3
  • OS: Linux
  • Additional Library Versions: N/A

Additional context/Screenshots

N/A

@mattfredericksen
Copy link

mattfredericksen commented Oct 6, 2021

Seems to be related to #4111 / #4130. Appears to be fixed by #4116.

@roj1512
Copy link
Author

roj1512 commented Oct 7, 2021

Is it fixed or made a problem by #4116?

@balassanne
Copy link

I have a similar problem I think...
Previous to axios 0.22.0 I could use the following line of code:

const responseBody = <T> (response: AxiosResponse<T>) => response.data;

const requests = {
post: <T>(url: string, body: {}) => axios.post<T>(url, body).then(responseBody)
}

After updating, I get an error saying: "Argument of type '{}' is not assignable to parameter of type 'T' . 'T' could be instantiated with an arbitrary type which could be unrelated to '{}' .

There are a lot more broken in my axios code when moving from 0.21.4 to 0.22.0. I guess I will stick to 0.21.4 ...

@remcohaszing
Copy link
Contributor

This is a duplicate of #4109 which was fixed by #4116

@karlhorky
Copy link
Contributor

@rojserbest can you confirm that this is fixed now and if so, close this issue?

@roj1512
Copy link
Author

roj1512 commented Oct 15, 2021

It was fixed. I would prefer data was any instead of unknown, anyway.

@roj1512
Copy link
Author

roj1512 commented Oct 15, 2021

Closing this.

@roj1512 roj1512 closed this as completed Oct 15, 2021
@karlhorky
Copy link
Contributor

Thanks!

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

5 participants