【问题标题】:Type mismatch with Firestore Observer类型与 Firestore 观察者不匹配
【发布时间】:2020-10-09 18:59:29
【问题描述】:

我正在使用 google 的 firestore 数据库系统以及 Angular 和 NgRx 以及 NgRx Entity and Data 开发一个应用程序。

我想调用数据库并将数据作为给定类型(设计)的可观察数组返回。问题是firestore返回的observable不是我需要的类型,所以这个函数不起作用。我应该遍历数据并设置每个项目吗?有没有我想强制输入的地方?调用是否不起作用并因此返回错误?

这是对 firebase 服务的调用。

    return this.afs.collection('designs', ref => ref
        .where('status', '==', 1 )
        .where('deleted', '==', false))
        .valueChanges();

npm start 中的错误消息

Type 'Observable<unknown[]>' is not assignable to type 'Observable<makDesign[]>'.

【问题讨论】:

    标签: angular firebase google-cloud-firestore ngrx


    【解决方案1】:

    我设法通过强制 observable 的类型来解决这个问题。我想知道是否还有更微妙的东西。

        return <Observable<design[]>> this.afs.collection('designs', ref => ref
            .where('status', '==', 1 )
            .where('deleted', '==', false))
            .valueChanges()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-22
      • 1970-01-01
      相关资源
      最近更新 更多