Search code examples
typescriptangularfire2

How to type with typescript a angularfire observable?


I am trying to use angularfire properly and type it. But I always have this error :

 getMessages(): Observable<ChatMessage[]> {
    return this.db.collection('chat').valueChanges();

}enter image description here

I tried this workaround, but is not clean

 getMessages(): Observable<ChatMessage[]> {
    return <any>this.db.collection('chat').valueChanges();

Solution

  • You need to use

    this.db.collection<ChatMessage>('chat')
    

    As you can see here