0

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();
3
  • 1
    See if any of the methods in this.db.collection('chat').valueChanges() are generic. My bet is that collection is generic and this.db.collection<ChatMessage>('chat').valueChanges() should work. Commented Sep 16, 2018 at 17:31
  • Yes! Do you have any link to documentation about this ? Commented Sep 16, 2018 at 17:33
  • It was just a guess, based on how such APIs usually work :). The idea is that there is not enough info there to get to the ChatMessage type so you probably have to specify it somewhere, and collection seemed like a logical answer. Anyway, someone seems to have posted an answer with a link :) Commented Sep 16, 2018 at 17:35

2 Answers 2

3

You need to use

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

As you can see here

Sign up to request clarification or add additional context in comments.

Comments

0

If you're using RTDB:

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

as you can see here: https://github.com/angular/angularfire/blob/master/docs/rtdb/lists.md

1 Comment

Giving more details and explanation is always better.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.