【问题标题】:How do I fix the following error? property 'pipe' does not exist on type OperatorFunction如何修复以下错误?类型 OperatorFunction 上不存在属性“管道”
【发布时间】:2018-11-25 22:32:15
【问题描述】:

我按照 RxJS 6 文档编写了以下代码。我目前正在运行 angular 5、RxJS 6 和 angularfire2 rc.10。我得到的错误是

[ts] property 'pipe' does not exist on type 'OperatorFunction<{}, [{}, user, string]>'.

这是代码

this.companies$ = combineLatest(this.authService.user$, this.filter$).pipe(
  switchMap(([user, filter]) =>
    this.afs.collection("companies", ref => {
        if (user) {
          ref.where("owner.network", "==", user.activeNetworkProfile.id);
        }
        if (user) {
          ref.where("name", "==", filter);
        }
        return ref;
      }).valueChanges()
  )
);

this.authService.user$ 和 this.filter$ 是可观察的。

public filter$: Observable<string>;
public user$ : Observable<User>;

【问题讨论】:

  • 你确定使用 rxJs 6 吗? angular 5 出现并与 rxJs 5 一起使用。我不认为混合这些版本是一个好主意

标签: angular typescript rxjs angularfire2 rxjs6


【解决方案1】:

您尚未显示导入语句,但从错误消息的外观来看,您似乎导入了错误的 combineLatest 函数。

RxJS6 有两个combineLatest 函数:

  • 可管道操作符:import {combineLatest} from 'rxjs/operators'
  • 创建方法:import { combineLatest } from 'rxjs'

您正在使用创建方法,因此导入应该来自'rxjs',而不是来自'rxjs/operators'

【讨论】:

  • 这很好用,我需要回去重新阅读可观察对象的工作原理。有什么推荐的文章吗?
猜你喜欢
  • 2018-10-28
  • 1970-01-01
  • 2018-09-27
  • 2019-06-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-12
  • 2020-02-22
相关资源
最近更新 更多