I am currently retrieving a collection from Firebase and attempting to iterate over the collection, returning instances of objects. Here is what my code looks like:
class Todo {
constructor(public text: string) { }
}
this.db.list('todos').map(todo => {
return new Todo(todo);
});
Although this solution works, I encounter a TypeScript intellisense error on the new Todo(todo)
line which states:
Argument of type 'any[]' is not assignable to parameter of type 'string'.
I have noticed that this.db.list
returns a type of
FirebaseListObservable<any[]>
. However, when I debug this line and check the type of todo
, it indicates that it is a string rather than an array of any type.
I am unsure about how to resolve this issue with TypeScript.
Update
After investigation, it came to light that the error was due to a mistake on my part. In one of my tests, I had incorrectly mocked the observable response from Firebase, leading me to misinterpret the results. Cartant's answer helped me see through this misunderstanding.