'OperatorFunction<HttpResponse<any>, number>' 类型的角度错误参数不可分配给 'OperatorFunction<HttpResponse<Object>, unknown>'

时间:2021-05-03 17:39:45

标签: angular typescript

在 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);
  }

我收到以下错误:

  • 错误 TS2345:“OperatorFunction”类型的参数不可分配给“OperatorFunction”类型的参数。 参数“source”和“source”的类型不兼容。 “Observable”类型中缺少“_deprecatedSyncErrorSubscribe”属性,但“Observable”类型中需要该属性。

关于需要调整什么才能使其工作的任何想法?可能返回类型必须是显式的?

0 个答案:

没有答案