【发布时间】:2018-10-23 13:16:36
【问题描述】:
combineLatest 函数可以从 rxjs 和 rxjs/operators 导入。
当我从 rxjs/operators 导入它时(就像我导入 combineAll 一样,我收到以下错误:
TS2339: Property 'subscribe' does not exist on type 'OperatorFunction<{}, [{}, number, number, number]>'
我使用了以下代码sn-p:
import { timer } from "rxjs";
import { combineLatest } from "rxjs/operators";
const timerOne = timer(1000, 2500);
const timerTwo = timer(1500, 2500);
const timerThree = timer(2000, 2500);
//when one timer emits, emit the latest values from each timer as an array
const combined$ = combineLatest(timerOne, timerTwo, timerThree);
combined$.subscribe(
([timerValOne, timerValTwo, timerValThree]) => console.log(`Timer One Latest: ${timerValOne}, Two Latest: ${timerValTwo}, Three Latest: ${timerValThree}`)
);
因此,我尝试从 rxjs 而不是 rxjs/operators 导入它:
import { combineLatest } from "rxjs";
突然间它起作用了。很好,但是谁能解释一下两者之间的区别?
【问题讨论】:
标签: typescript rxjs