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

(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 this issue May 12, 2022 · 1 comment

Comments

@dialmedu
Copy link

dialmedu commented May 12, 2022

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.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

image

@MagicHacker
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants