为什么我的httpclient中的rxjs管道函数返回Observable <response | =“”myclass =“”>

时间:2018-05-09 02:06:26

标签: angular rxjs httpclient

在此代码中

getHero(id: number): Observable<Hero> {
  const url = `${this.heroesUrl}/${id}`;
  return this.http.get<Hero>(url).pipe(
    tap(_ => this.log(`fetched hero id=${id}`)),
    catchError(this.handleError<Hero>(`getHero id=${id}`))
  );
}

来自Angular文档here 工作正常,而在我的项目中,&#34;相同&#34;代码给了我错误

  

错误TS2322:键入&#39; Observable&#39;不能分配给&#39; Observable&#39;。

升级到角度6?

public getCustomer(customerRecId: string): Observable<Customer> {
  const url = `${this.baseUrl}/Customer?recId=${customerRecId}`;
  const customer$ = this.http.get(url, this.httpOptions).pipe(
    map(this.mapCustomer), 
    catchError(this.handleError)
  );

  return customer$;
}

将鼠标悬停在&#39; .pipe&#39;在vsCode中,在前一个示例中显示它返回一个Observable,但在后者中返回一个Observable

我不明白为什么这两个例子不同。

0 个答案:

没有答案