【发布时间】:2021-08-29 21:52:16
【问题描述】:
我正在尝试使用combineLatest,特别是我需要将四个发出不同类型值的 Observable 与一个返回布尔类型的投影函数结合起来。
根据我从Rxjs documentation here 得到的信息,我认为这是我需要使用的combineLatest 签名,它没有被弃用:
combineLatest(sources: readonly any[], resultSelector: (...values: A) => R): Observable<R>
在我的情况下,R 是 boolean。
这是我尝试使用该函数的代码 sn-p,但 Visual Studio Code 显示带有删除线样式的调用,并且表明它已被弃用。
this.canBook$ = combineLatest(
this.userSvc.canRedirect(this.fbSvc.getUserId()),
this.userSvc.canBook(this.fbSvc.getUserId()),
this.calSvc.segnaleOrarioIso8601(),
this.selectedDay$,
(canredir: boolean, canbook: boolean, iso8601: string, selday: ICGiorno) => {
return canredir && (dayjs(selday.iso8601).diff(iso8601, 'hour') > 0) ||
canbook && (dayjs(selday.iso8601).diff(iso8601, 'hour') >= 24);
} );
VS Code 说:
The signature '(v1: Observable<boolean>, v2: Observable<boolean>, v3: Observable<string>, v4: Subject<ICGiorno>, resultSelector: (v1: boolean, v2: boolean, v3: string, v4: ICGiorno) => boolean, scheduler?: SchedulerLike): Observable<...>' of 'combineLatest' is deprecated.ts(6387)
但是我没有传入任何调度程序参数,所以我不明白为什么 VS Code 将我的调用与不推荐使用的签名匹配,而不是上面 Rxjs API 文档中记录的签名。
你能帮我理解为什么吗?
【问题讨论】:
-
您使用的是 rxjs v6 吗?看起来 resultSelector 将被弃用 (
combineLatest@6.67),但在 v7 中似乎并非如此:combineLatest@latest -
@BizzyBob 是的,我使用的是 v6,但即使更新到 v7 也没有使弃用警告消失。
标签: syntax rxjs deprecated deprecation-warning combinelatest