[英]Multicast Operator with Pipe in RxJS 5.5+
How do I use the multicast()
operator with the new recommended approach in RxJS 5.5 of using pipe()
instead of chaining operators? 如何在RxJS 5.5中使用
pipe()
而不是链接运算符的新推荐方法来使用multicast()
运算符? I get a TypeScript error when I try to use connect()
like I did before: 当我像以前一样尝试使用
connect()
时,出现TypeScript错误:
const even$ = new Subject();
const connectedSub = interval(500)
.pipe(
filter(count => count % 2 === 0),
take(5),
multicast(even$)
)
.connect();
even$.subscribe(value => console.log(value));
This code works but yields a TypeScript error that reports that Property 'connect' does not exist on type 'Observable<{}>'.
此代码有效,但会产生TypeScript错误,该错误报告
Property 'connect' does not exist on type 'Observable<{}>'.
Am I using connectable observables the way that I should be in RxJS 5.5+? 我是否以我在RxJS 5.5+中应该使用的方式使用可连接的可观察对象?
The current - v5.5.10 and v6.1.0 - typings for pipe
are not aware of the Observable
subclasses, so I use a type assertion, like this: 当前的-v5.5.10和v6.1.0-
pipe
类型不知道Observable
子类,因此我使用类型断言,如下所示:
const connectedObs = interval(500).pipe(
filter(count => count % 2 === 0),
take(5),
multicast(even$)
) as ConnectableObservable<number>;
const connectedSub = connectedObs.connect();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.