当我更新到 RxJS 6 时,我的应用程序崩溃了。我的大部分工作都正常,但这个方法让我难住了。
之前,我们有一个可观察数组被平面映射,然后像这样使用combineLatest:
const newObservable = myArrayOfObservables
.flatMap(observables => {
return Observable.combineLatest(observables);
});
我可以订阅 newObservable 并从所有其他人那里获取最新输出的数组。
现在我正在尝试做这样的事情:
const mergedList$ = chatList$.pipe(
mergeMap(res => {
return combineLatest(res);
}));
这给了我一个非常长且令人费解的内容
Argument of type '(res: Observable<{ $key: string; }>[]) => OperatorFunction<{}, [{}, Observable<{ $key: string; }>]>' is not assignable to parameter of type '(value: Observable<{ $key: string; }>[], index: number) => ObservableInput<{}>'. Type 'OperatorFunction<{}, [{}, Observable<{ $key: string; }>]>' is not assignable to type 'ObservableInput<{}>'. Type 'OperatorFunction<{}, [{}, Observable<{ $key: string; }>]>' is not assignable to type 'Iterable<{}>'. Property '[Symbol.iterator]' is missing in type 'OperatorFunction<{}, [{}, Observable<{ $key: string; }>]>'.
坦率地说,我的阅读障碍使我无法解析。
如果我只是在上面返回res,然后尝试
const mergeCombo = combineLatest(mergedList$);
现在 mergeCombo 不是可观察的。相反,它是一个
OperatorFunction<{}, [{}, Observable<{ $key: string; }>]>
值得注意的是,我的原始可观察值是由 AngularFireObject.snapshotChanges() 发出的
最佳答案
您没有显示如何导入combineLatest
。看起来您正在将其作为运算符导入,但该运算符已被弃用。
确保像这样导入它:
import {combineLatest} from "rxjs";
那么你的原始代码应该可以正常工作:
const mergedList$ = chatList$.pipe(
mergeMap(res => combineLatest(res))
);
关于firebase - 无法订阅combineLatest的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50977141/