【发布时间】:2021-05-19 19:36:59
【问题描述】:
我有以下代码
const mySource:Observable<Observable<any>[]>
(...)
mySource.pipe(
switchMap(arr=>forkJoin(arr));
)
按预期工作,但是
mySource.pipe(
switchMap(forkJoin);
)
失败
REST error TypeError: You provided '0' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
RxJS 31
subscribeTo
from
forkJoinInternal
_trySubscribe
subscribe
innerSubscribe
_innerSub
为什么第二个变种不起作用?
Stackblitz:https://stackblitz.com/edit/typescript-tztgpl?file=index.ts
请记住,这是一个运行时错误,而不是与 IDE 相关的内容。
【问题讨论】:
-
我相信这是因为
forkJoin的类型签名不能分配给switchMap回调类型。可能是因为switchMap期望第二个参数的类型与forkJoin的第二个参数不同。你用的是哪个版本的 rxjs? -
Intellij 实际上喜欢更多不起作用的变体,并抱怨在工作选项中不推荐使用 forkJoin ;) rxjs verion "version": "6.6.3",
-
我认为问题出在 IDE 而不是类型。这里stackblitz.com/edit/typescript-4deq3j?file=index.ts同样的例子没有类型错误
-
但是这个错误是一个运行时错误——我完全忽略了 IDE 所说的任何内容。
标签: typescript rxjs