在 Angular 库中,我们使用的代码在将 typescript 版本升级到大于 4 后无法编译。
login(_username: string, _password: string): Observable<boolean> {
return this._http.post(
this.directLoginLocation(),
{username: _username, password: _password},
{observe: "response"}
).pipe(map((resp: HttpResponse<any>) => {
if (resp.status === 201) {
return true;
} else {
throw new Error("Authentication failed. " + resp.status + ": " + resp.statusText);
}
}),
catchError(this.handleError));
}
handelError 函数定义为:
private handleError(error: any) {
let errMsg = (error.message) ? error.message : AuthenticationService.GENERIC_ERR_MSG;
return Observable.throw(errMsg);
}
我收到以下错误:
关于需要调整什么才能使其工作的任何想法?可能返回类型必须是显式的?