Typescript RxJS CombineTest函数可以从RxJS和RxJS/运算符中导入,两者的区别是什么?
CombineTest函数可以从rxjs和rxjs/operators导入 当我从rxjs/operators导入它时(就像导入combineAll一样),我会得到以下错误:Typescript RxJS CombineTest函数可以从RxJS和RxJS/运算符中导入,两者的区别是什么?,typescript,rxjs,Typescript,Rxjs,CombineTest函数可以从rxjs和rxjs/operators导入 当我从rxjs/operators导入它时(就像导入combineAll一样),我会得到以下错误: TS2339: Property 'subscribe' does not exist on type 'OperatorFunction<{}, [{}, number, number, number]>' 因此,我尝试从rxjs而不是rxjs/operators导入它: 突然,它起了作用。很好,但是有人能
TS2339: Property 'subscribe' does not exist on type 'OperatorFunction<{}, [{}, number, number, number]>'
因此,我尝试从rxjs而不是rxjs/operators导入它:
突然,它起了作用。很好,但是有人能解释两者之间的区别吗
从“rxjs”导入{combinelatetest};
这就是所谓的“Observable creation method”。基本上是一种基于您传递的参数返回Observable的方法(就像from()
或of()
从“rxjs/operators”导入{combinelatetest};
这是一个应该在操作符链中使用的操作符。它是一个返回另一个方法的方法,该方法订阅前面的可观察对象,并返回另一个可观察对象,该可观察对象处理其输出中经过的每个值
这就是为什么它会给您一个错误,
属性“subscribe”在类型上不存在……
。subscribe()
方法在从CombineTest()
操作符返回的方法上不存在(它返回另一个函数)
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}`)
);
import { combineLatest } from "rxjs";