如何使用打字稿输入 angularfire observable?

How to type with typescript a angularfire observable?

我正在尝试正确使用angularfire并输入它。但我总是有这个错误:

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

}

我试过这个解决方法,但不干净

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

您需要使用

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

如你所见here

如果您使用的是 RTDB:

this.db.list<ChatMessage>('chat');

如您所见:https://github.com/angular/angularfire/blob/master/docs/rtdb/lists.md