我如何重构这一点:
const warmObservable = this.httpClient.get<Result[]>(url).publishLast();
warmObservable.connect();
可出租运营商?
当我使用时:
const warmObservable = this.httpClient.get<Result[]>(url).pipe(publishLast());
warmObservable.connect();
我收到错误:
Property 'connect' does not exist on type 'Observable<any>'.
使用的版本:[email protected]
最佳答案
pipe
方法始终返回 Observable
,如您在此处看到的:https://github.com/ReactiveX/rxjs/blob/master/src/Observable.ts#L293
所以你需要自己进行类型转换。
const warmObservable = this.httpClient.get<Result[]>(url).pipe(publishLast()) as ConnectableObservable;
warmObservable.connect();
关于angular - 使用lettable的publishLast运算符时如何获取ConnectableObservable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47155043/