typescript - 在 Typescript 中使用不同类型的 RxJS 扫描累加器和更新值
问题描述
尝试使用不同类型的 RxJS 进行“输入和输出”:
a$: Subject<Request>;
b$: Observable<Pair[]>;
在我传递请求的地方,它在scan
函数中得到处理,并添加到累加器中:
this.b$ = this.a$.pipe(
startWith([]),
scan(this.accumulator),
shareReplay(),
);
accumulator(acc: Pair[], modification: Request): Pair[] {
// .... process request and add the pair derived from request to acc
return acc
}
但是 typescript 立即开始抱怨累加器不适用于定义的类型,并且它只适用于 setting modification: any
,这就像根本不写 typescript 一样。
我对 Rx 有误解吗?当我进入运行时,这种模式以前对我有用。
解决方案
不知道您是否找到了答案,但您所要做的就是拆分主题和观察者定义:
推荐阅读
- python - 斯坦福在 python 中使用 coreNLP 键入依赖项
- javascript - 更改属性时如何抛出错误?
- mysql - 将两列之间的时间差计算为表中的另一列 AFTER\BEFORE INSERT
- python-2.7 - 在 def 函数中调用 Dataframe()
- stm32 - STM32 SPI 带宽评估程序
- ios - `relationshipKeyPathsForPrefetching` 不起作用
- xamarin - [QueryProperty("Name", "name")] 在 Xamarin Shell 应用程序中的用途是什么?
- ios - 如何在 SwiftUI 中使用 URLSession 请求后呈现视图?
- sublimetext3 - 使用 Sublime Text 查找/替换向输入标签添加属性
- azure - 尝试向用户添加架构扩展时权限不足