Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'AxiosRequestConfig' is not assignable to parameter of type 'AxiosRequestConfig<any>'

Tags:

axios

nestjs

I got this error about AxiosRequestConfig, it's really specific, but still can't find in Google. Any tips? thanks

Argument of type 'AxiosRequestConfig' is not assignable to parameter of type 'AxiosRequestConfig<any>'.
  Types of property 'adapter' are incompatible.
    Type 'import("/Users/apple/Dev/back-end-api/node_modules/axios/index").AxiosAdapter' is not assignable to type 'import("/Users/apple/Dev/back-end-api/node_modules/@nestjs/axios/node_modules/axios/index").AxiosAdapter'.
      Types of parameters 'config' and 'config' are incompatible.
        Type 'AxiosRequestConfig<any>' is not assignable to type 'AxiosRequestConfig'.
          Types of property 'transitional' are incompatible.
            Type 'import("/Users/apple/Dev/back-end-api/node_modules/@nestjs/axios/node_modules/axios/index").TransitionalOptions' is not assignable to type 'import("/Users/apple/Dev/back-end-api/node_modules/axios/index").TransitionalOptions'.
              Property 'silentJSONParsing' is optional in type 'TransitionalOptions' but required in type 'TransitionalOptions'.

My code is like below, a simple AxiosRequestConfig, and Visual Studio Code flags the param config in this.httpService.get<LoginResponse>(MAILAPI_LOGIN_PATH, config)

 private _loginAndChangeToken(): Observable<LoginResponse> {
    const config: AxiosRequestConfig = {
      auth: {
        username: MAILAPI_USERNAME,
        password: MAILAPI_PASSWORD,
      },
    };
    return this.httpService.get<LoginResponse>(MAILAPI_LOGIN_PATH, config).pipe(
      map((response) => response.data),
      tap(({ token }) => {
        this.token = token;
      }),
    );
  }

I'm using NestJs axios, and the dependency is:

"@nestjs/axios": {
      "version": "0.0.3",
      "resolved": "https://registry.npmjs.org/@nestjs/axios/-/axios-0.0.3.tgz",
      "integrity": "sha512-Cc+D2S2uesthRpalmZEPdm5wF2N9ji4l9Wsb2vFaug/CVWg2BoegHm0L1jzFUL+6kS+mXWSFvwXJmofv+7bajw==",
      "requires": {
        "axios": "0.23.0"
      },
like image 322
EyeQ Tech Avatar asked Oct 25 '25 04:10

EyeQ Tech


2 Answers

Just use InternalAxiosRequestConfig instead of AxiosRequestConfig

like image 160
TuAnh Nguyen Avatar answered Oct 26 '25 23:10

TuAnh Nguyen


Here for anyone needs: turned out the axios verion in my package.json is different from my teammate's. I deleted all my node modules, made sure I use the correct package.json file and did a clean install via npm ci and it worked.

like image 37
EyeQ Tech Avatar answered Oct 27 '25 01:10

EyeQ Tech