axios-module
axios-module copied to clipboard
(config: AxiosRequestConfig): AxiosPromise<any>', gave the following error. Argument of type 'AxiosRequestConfig<any>' is not assignable to parameter of type 'AxiosRequestConfig'
I get the following error message with the release version v15.3.16
No overload matches this call.
Overload 1 of 2, '(config: AxiosRequestConfig): AxiosPromise<any>', gave the following error.
Argument of type 'AxiosRequestConfig<any>' is not assignable to parameter of type 'AxiosRequestConfig'.
Overload 2 of 2, '(url: string, config?: AxiosRequestConfig): AxiosPromise<any>', gave the following error.
Argument of type 'AxiosRequestConfig<any>' is not assignable to parameter of type 'string'.
49 |
50 | flushPendingRequests(null);
> 51 | resolve($axios(originalRequest));
| ^^^^^^^^^^^^^^^
52 | } catch (e) {
53 | console.log('refreshing token failure ...'); // eslint-disable-line
54 | e.status = 403;`
I am trying to use the following code
const originalRequest: AxiosRequestConfig = error.config; // get AxiosRequesConfig<any>
if (isAuthError(error)) {
if (isReAuthenticating) {
return new Promise((resolve, reject) => {
pendingRequests.push({ resolve, reject });
})
.then(() => {
return $axios(originalRequest); // required AxiosRequestConfig
})
.catch((err) => {
return Promise.reject(err);
});
}
The error is because error.config returns an AxiosRequesConfig<any> and to create an instance of axios the config argument is of type AxiosRequesConfig, therefore they are not compatible
In the release version v5.13.6 uses axios version 0.21.1 this version does not use AxiosRequesConfig<any>

With Axios version 0.25.0 the problem is solved, it is required in the main branch but not in the release version. [v15.3.16](https://github.com/nuxt-community/axios-module/blob/v5.13.6/package.json#L24) it is downloaded by default with the command npm i @nuxtjs/axios it is not compatible with libraries that use only Axios

Config inside interceptors has a different interface. If you explicitly specify the config type, use InternalAxiosRequestConfig instead of AxiosRequestConfig. AxiosRequestConfig is the external/raw config interface.
axios.interceptors.request.use(async (config: InternalAxiosRequestConfig) => {
});
const config: AxiosRequestConfig = {};
axios(config);