When I make a call to axios, I include a config object like this:
const req = { method, url, timeout: 300000, headers: { 'Content-Type': 'application/json' } }
axios(req)
An error in TypeScript is thrown stating that "No overload matches this call". The axios function expects a config object of type AxiosRequestConfig
:
axios(config: AxiosRequestConfig): AxiosPromise<any>
Here are the details for the AxiosRequestConfig
type and the Method
type:
interface AxiosRequestConfig {
url?: string;
method?: Method;
...
}
type Method =
| 'get' | 'GET'
| ...
The error seems odd considering my config object aligns with the interface. Interestingly, changing the type definition of AxiosRequestConfig
from
method?: Method
to
method?: String;
makes the TypeScript error disappear. Similarly, explicitly adding the method property when spreading the config object like this:
axios({...req, method: 'GET'})
resolves the error. However, simply spreading in the config object triggers the initial issue.
This situation suggests a potential connection between the error and the method property of the AxiosRequestConfig interface, although it's not entirely clear. Any insights or assistance would be greatly appreciated. Thank you.