类型'Observable <httpevent <any>&gt;'上不存在属性'catchError'

时间:2018-06-06 22:40:19

标签: angular typescript rxjs observable rxjs6

从角度5到6(使用角度6&amp; rxjs 6),在我的linter中得到以下两个错误。请有任何想法,谢谢。

[ts] 'catchError' is declared but its value is never read.
[ts] Property 'catchError' does not exist on type 'Observable<HttpEvent<any>>'.
import { Injectable, Injector } from '@angular/core';
import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http';
import { catchError } from 'rxjs/operators';
import { Observable } from 'rxjs';



@Injectable()
export class HttpInterceptorService implements HttpInterceptor {
  constructor() { }

  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {

    return next.handle(authReq)
      .catchError((error, caught) => {
        console.log('Error Occurred');
        console.log(error);
        return Observable.throw(error);
      }) as any;
  }
}

1 个答案:

答案 0 :(得分:4)

这更像是rxjs的变化。你想要让自己熟悉lettable操作员,但是你想要做的代码改变......

feature/X.<number>

非常简单吧!现在大多数rxjs运算符都被传递给了observable的expireUnreachable函数!