The 结合最新函数可以从以下位置导入rxjs和来自rxjs/运算符.
当我导入它时rxjs/运算符(就像我导入合并所有我收到以下错误:
TS2339: Property 'subscribe' does not exist on type 'OperatorFunction<{}, [{}, number, number, number]>'
我使用了以下代码片段:
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/运算符 :
import { combineLatest } from "rxjs";
突然间它起作用了。很好,但有人能解释一下两者之间有什么区别吗?