【问题标题】:Argument of type '"==="' is not assignable to parameter of type 'WhereFil terOp''"==="' 类型的参数不能分配给 'WhereFilterOp' 类型的参数
【发布时间】:2019-10-30 12:22:13
【问题描述】:

我正在尝试为 firebase 集合引用创建 where 子句:

this.allItineraries = firebase
            .firestore()
            .collection(`itinerary`);

这里是 where 子句:

      return this.allItineraries.where('userId', '===', this.userId);

但是程序不会编译并给出以下错误:

[ng] src/app/services/data.service.ts(45,55) 中的错误:错误 TS2345: '"==="' 类型的参数不能分配给类型参数 'WhereFil

where 子句看起来与我在 firebase 示例中看到的相同。

【问题讨论】:

  • 它是否适用于“==”?我还没有使用角火,但我看到文档支持“==”。 github.com/angular/angularfire2/blob/master/docs/firestore/…
  • firebase.google.com/docs/firestore/query-data/queries: 比较可以是, >=, or array_contains
  • 当我将其更改为 '==' 时,我得到以下信息: src/app/services/data.service.ts(49,7) 中的错误:错误 TS2322:类型 'Query' 不是可分配给类型“CollectionReference”。 [ng] 类型“查询”中缺少属性“id”。
  • 我也试过这个: const ref = this.allItineraries('id'); return ref.where('userId', '==', this.userId 并得到以下错误; src/app/services/data.service.ts(49,19) 中的错误:错误 TS2349:无法调用其表达式类型缺少调用签名。类型“CollectionReference”没有兼容的调用签名。
  • .where() 返回一个查询,而不是 CollectionReference。

标签: angular typescript firebase google-cloud-firestore ionic4


【解决方案1】:

问题是我试图在集合引用上使用查询。我必须从集合中创建一个查询,然后将该查询用于 onSnapshot 方法。

【讨论】:

    猜你喜欢
    • 2022-11-11
    • 1970-01-01
    • 2019-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-05
    • 1970-01-01
    • 2018-12-26
    相关资源
    最近更新 更多