【问题标题】:'AxiosRequestConfig' is not assignable to parameter of type 'AxiosRequestConfig<any>'“AxiosRequestConfig”不可分配给“AxiosRequestConfig<any>”类型的参数
【发布时间】:2021-12-25 09:34:46
【问题描述】:

我收到这个关于 AxiosRequestConfig 的错误,它非常具体,但在 Google 中仍然找不到。有小费吗?谢谢

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

我的代码如下,一个简单的 AxiosRequestConfig,Visual Studio Code 在this.httpService.get&lt;LoginResponse&gt;(MAILAPI_LOGIN_PATH, config) 中标记参数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;
      }),
    );
  }

我用的是NestJs axios,依赖是:

"@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"
      },

【问题讨论】:

    标签: axios nestjs


    【解决方案1】:

    这里满足任何人的需要:原来我的 package.json 中的 axios 版本与我队友的不同。我删除了所有节点模块,确保使用正确的 package.json 文件并通过 npm ci 并且成功了。

    【讨论】:

      猜你喜欢
      • 2021-09-10
      • 2021-01-26
      • 2018-03-19
      • 2020-03-19
      • 2021-12-05
      • 2021-06-10
      • 2019-09-06
      • 2019-01-09
      • 2019-11-02
      相关资源
      最近更新 更多