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

Issue with Axios #1539

Closed
maxsalven opened this issue Nov 16, 2017 · 2 comments
Closed

Issue with Axios #1539

maxsalven opened this issue Nov 16, 2017 · 2 comments
Labels
bug libdef Related to a library definition

Comments

@maxsalven
Copy link

It seems the libdef expects response.data to match the shape of submitted data in a post request? I think this is incorrect?

    axios({
      method: "post",
      url: "/user/12345",
      data: {
        firstName: "Fred",
        lastName: "Flintstone",
      },
    }).then(response => {
      console.log(response.data.wasSuccess);
    });

This raises a Flow error saying wasSuccess not found in object literal (whereas accessing response.data.firstName doesn't raise an error).

The user should be able to define the expected shape of response.data.

cc @timothystewart6 @haines

@haines
Copy link
Contributor

haines commented Nov 16, 2017

I think the problem is here, where the input config has the same type parameter as the output promise.

@cyorobert
Copy link

cyorobert commented Dec 28, 2017

Same issue here. What I'd like to be able to do is something like this:

type MyType = {
    foo : string,
    bar : number
}

type Error = {
     error : string
}

type Response = MyType & Error

function post(payload) : Promise<Response> {
    return axios.post('/my-route', payload)
                .then(response => response.data)
                .catch(() => ({error : "an error occurred"}))
}

@gantoine gantoine added libdef Related to a library definition bug and removed libdef-issue labels Mar 21, 2018
AndrewSouthpaw pushed a commit that referenced this issue Mar 29, 2018
This PR adds a separate response type to axios calls, earlier the definitions
used the same infered type for config.data and response.data. This has been mentioned in #1975 and #1539.

But hopefully this wont break backwards compatability since I added the
original type (T) as default for the new response type (R). Also verified by tests.

As of now I have only updated the 0.18.x-version. But the same issue is present in earlier versions as well. If you think I should update the old ones as well I'd be happy to do so.

* Add separate response type to axios

THis commit adds a separate response type to axios calls, earlier the definitions
used the same infered type for config.data and response.data.

But hopefully this wont break backwards compatability since I added the
original type (T) as default for the new response type (R).

* Use AxiosPromise when testing types

* Test that types carries through
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug libdef Related to a library definition
Projects
None yet
Development

No branches or pull requests

5 participants