You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

RxJS combineLatest按非弃用语法调用被标记弃用问题咨询

原因说明

你触发弃用提示的核心原因是传参形式和你预期的未弃用签名不匹配:

  • 你找到的未弃用签名要求第一个参数是所有Observable组成的数组,第二个参数才是投影函数;
  • 你当前的写法是把4个Observable逐个作为独立参数传入,最后跟投影函数,这种重载本身就是RxJS官方标记的弃用重载,无论你是否传入可选的scheduler参数,只要匹配这个传参形式就会触发弃用提示。

修复方案

有两种合规的写法可以消除警告:

方案1:匹配你找到的未弃用签名

把所有Observable放到数组里作为第一个参数传入即可:

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); 
  } 
);

方案2:RxJS当前更推荐的pipe+map写法

官方现在更推荐把投影逻辑放到map操作符中处理,避免使用combineLatest的resultSelector参数:

import { map } from 'rxjs';

this.canBook$ = combineLatest([
  this.userSvc.canRedirect(this.fbSvc.getUserId()),
  this.userSvc.canBook(this.fbSvc.getUserId()),
  this.calSvc.segnaleOrarioIso8601(),
  this.selectedDay$
]).pipe(
  map(([canredir, canbook, iso8601, selday]: [boolean, boolean, string, ICGiorno]) => {
    return canredir && (dayjs(selday.iso8601).diff(iso8601, 'hour') > 0) || 
           canbook && (dayjs(selday.iso8601).diff(iso8601, 'hour') >= 24);
  })
);

内容的提问来源于stack exchange,提问作者Lucio Crusca

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.05 17:30:06