-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Comments
I think the problem is here, where the input config has the same type parameter as the output promise. |
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
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
It seems the libdef expects
response.data
to match the shape of submitteddata
in a post request? I think this is incorrect?This raises a Flow error saying
wasSuccess
not found in object literal (whereas accessingresponse.data.firstName
doesn't raise an error).The user should be able to define the expected shape of
response.data
.cc @timothystewart6 @haines
The text was updated successfully, but these errors were encountered: