我正在从 angular 5 迁移到 6,但我无法弄清楚新的可管道运算符语法。
考虑我的 Angular 5 http 拦截器
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
this.request = req;
//do stuff
return next.handle(this.request)
.do(event => {
//do logging stuff
},
err => {
//do error stuff
});
}
这是我尝试将其转换为pipe
方式
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
this.request = req;
//do stuff
return next.handle(this.request).pipe(
tap(event => {
//do logging stuff
},
err => {
//do error stuff
}));
}
但是,这不会编译 - 与pipe
函数有关的整个事情都带有以下错误的下划线。
Severity Code Description Project File Line Suppression State
Error TS2345 (TS) Argument of type 'MonoTypeOperatorFunction<{}>' is not
assignable to parameter of type 'UnaryFunction<Observable<HttpEvent<any>>,
Observable<any>>'.
Types of parameters 'source' and 'source' are incompatible.
Type 'Observable<HttpEvent<any>>' is not assignable to type
'Observable<{}>'.
Property 'source' is protected in type 'Observable<HttpEvent<any>>' but public in type 'Observable<{}>'. C:\Users\stas.levich\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\stas.levich\Documents\Projects\EEA.Projects\DEP\MassAir\Web\src\app\services\httpinterceptor.service.ts 44 Active