【问题标题】:Property 'pipe' does not exist on type 'OperatorFunction<unknown, [unknown, boolean, any]>类型 'OperatorFunction<unknown, [unknown, boolean, any]> 上不存在属性 'pipe'
【发布时间】:2020-06-20 22:31:15
【问题描述】:

使用 Angular 9,我需要根据返回两个 observables 的两种方法检查条件:

    return zip(this.authService.isSignedIn(), this.authService.getRole()).pipe(
      map(([isSignedIn, role]: [boolean, string]) => isSignedIn && role && role.toLowerCase() === 'admin')
    );

但我得到了错误:

 Property 'pipe' does not exist on type 'OperatorFunction<unknown, [unknown, boolean, any]>

我错过了什么?

【问题讨论】:

  • 你检查过你的进口吗?你确定 zip() 参数是可观察的吗?

标签: angular rxjs observable angular9


【解决方案1】:

这是一个常见的错误,你错误地导入了,确保你是从 rxjs 导入 zip 而不是从另一个命名空间

Import {zip} from "rxjs"

【讨论】:

  • 发现...我是从 'rxjs/operators' 导入的。谢谢。
【解决方案2】:

确保您直接从'rxjs' 导入zip。这不是一个操作符,而是 Observable 创建方法。 https://rxjs.dev/api/index/function/zip

'rxjs/operators' 中还有 zip 运算符,但在这种情况下您不希望这样。 https://rxjs.dev/api/operators/zip

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-16
    • 2020-04-09
    • 2021-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-25
    • 1970-01-01
    相关资源
    最近更新 更多