我一直不知道如何输入我的HttpResponse.我试图匹配我的API返回给我的内容,但Vim中的打字帮助一直告诉我:
typescript: Type 'Observable<unknown>' is not assignable to type 'Observable<string | HttpErrorResponse>'.
Type 'unknown' is not assignable to type 'string | HttpErrorResponse'. [2322]
我的帖子是这样的:
forgotPassword(args: {studentId: string, emailAddress: string}): RxObservable<HttpErrorResponse | string> {
const body = {
studentId: args.studentId,
emailAddress: args.emailAddress
}
console.log("forgot password", body)
return this.http
.post<HttpErrorResponse | string>(
`${this.nextApiEndpoint}Authentication/ForgotPassword`,
body,
{}
)
.pipe(
switchMap((data: string) => data),
catchError((err) => {
return err;
})
);
}
我正在try 使用SwitchMap来确保管道输出的数据是字符串,但我真的不需要这样做,因为这就是我的http响应已经是字符串.