【发布时间】: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<LoginResponse>(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"
},
【问题讨论】: