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

[TypeScript] fix Property 'then' does not exist on type 'AxiosInstance'. #1244

Closed
wants to merge 1 commit into from

Conversation

k1r0s
Copy link

@k1r0s k1r0s commented Dec 18, 2017

Using typescript. Creating an AxiosInstance with axios::create(...) the returned object cannot be used like this:

import axios from "axios";

const axiosInstance = axios.create({
  baseURL: 'whatever.api',
  timeout: 1000,
  headers: {
    "Content-Type": "application/x-www-form-urlencoded"
    "stuff"..
  },
  withCredentials: true
});

axiosInstance({
   method: "post",
   url: "/resource"
}).then(res => console.log(res.data))
// err 

In javascript this is working perfectly but in typescript you get an error because of wrong typings.

Typings specify that you can do AxiosInstance.get().then or AxiosInstance.put().then but doesn't allow you to do the same as with AxiosStatic and this isn't correct.

The error from TypeScript:
Cannot invoke an expression whose type lacks a call signature. Type 'AxiosInstance' has no compatible call signatures.

My fix properly sets function signatures to axiosInstance and then axiosstatic will extend those signatures as expected.

Its sad that almost nobody uses typescript :(

Any comments appreciated

@nickuraltsev
Copy link
Member

Closing in favor of #1192. Thank you for the PR!

@axios axios locked and limited conversation to collaborators May 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants