nuxt-community / axios-module

Secure and easy axios integration for Nuxt 2
https://axios.nuxtjs.org
MIT License
1.2k stars 245 forks source link

(config: AxiosRequestConfig): AxiosPromise<any>', gave the following error. Argument of type 'AxiosRequestConfig<any>' is not assignable to parameter of type 'AxiosRequestConfig' #576

Open dialmedu opened 2 years ago

dialmedu commented 2 years ago

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>

image

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.16it is downloaded by default with the commandnpm i @nuxtjs/axios` it is not compatible with libraries that use only Axios

image

MagicHacker commented 1 year ago

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);