合并弃用警告混淆

时间:2020-09-03 07:51:50

标签: rxjs

使用RXJS,我有以下内容

      merge(this.optionValueChanged$, this.options.changes).subscribe(() => {
        this.selectionByValue(this.pValue)
      }),

现在,悬停时返回

@deprecated-使用{@link Scheduled}和{@link mergeAll}(例如`scheduled([ob1,ob2,ob3],Scheduled).pipe(mergeAll())

但是我阅读了有关计划的内容,并且看起来它并没有完全按照我的意愿进行。而且,我无法弄清楚方法scheduled中的scheduled代表什么。

3 个答案:

答案 0 :(得分:4)

Typescript选择错误的重载。不推荐使用仅接受SchedulerLike的重载。

尝试更改参数的顺序

merge(this.options.changes, this.optionValueChanged$)

或将它们包装成阵列并散布

merge(...[this.optionValueChanged$, this.options.changes])

答案 1 :(得分:3)

我同意,这令人困惑。我一直以这种方式将其视为any,它是可观察对象的占位符,并发出其他可观察对象。

看看这个例子

const ob1 = of(1).pipe(delay(5000));
const ob2 = of(2).pipe(delay(1000));
const ob3 = of(3).pipe(delay(2000));

function schedule() {
  return of(ob1, ob2, ob3);
}

schedule().pipe(
  mergeAll(),
).subscribe(console.log);

它具有与merge相同的功能,因为它最后发出,所以最后打印1。

请参阅stackblitz:https://stackblitz.com/edit/rxjs-z6t8yn?file=index.ts

答案 2 :(得分:2)

也遇到了这个问题,当我在传入 merge 之前明确定义参数类型时解决了。

const obs1: ObservableInput<any> = ...
const obs2: ObservableInput<any> = ...
return merge(obs1, obs2).pipe(...)