我得到了这个关于AxiosRequestConfig的错误,它真的很具体,但仍然无法在谷歌中找到。任何提示?谢谢
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代码标记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"
},
2条答案
按热度按时间ymzxtsji1#
这里满足任何人的需求:我发现我的package.json中的axios版本与我的队友的不同。我删除了所有节点模块,确保使用正确的package.json文件,并通过
npm ci
进行了全新安装,它工作正常。5vf7fwbs2#
我不得不改变
import AxiosRequestConfig from "axios";
到
import { AxiosRequestConfig } from "axios";
这为我解决了这个问题。