1

I'm using the angularfire2 version 5 and i'm getting the following error:

Type 'Observable<{}[]>' is not assignable to type Observable < any [] >.

This is my code:

 exercisesList$: Observable <any[]>; ionViewDidLoad() { this.exercisesList$ = this.workoutProvider.getExercises(); } 

getExercises()

 getExercises(){ return this.db.list(`Exercises/${localStorage.getItem('workoutName')}`).valueChanges(); } 

HTML

 <ion-list> <ion-item *ngFor="let exercise of exercisesList$ | async">{{exercise.name}}</ion-item> </ion-list> 

Screenshot

enter image description here

Any one can explain what is the type of valueChanges and how can i solve this issue.

Thanks.

1 Answer 1

3

There is currently an open issue regarding this:

https://github.com/angular/angularfire2/issues/1299

You have two ways of solving it:

  • Following transpiler tips, you can simply change the exercisesList$ type to Observable <{}[]>

  • Cast the return type:

this.exercisesList$ = this.workoutProvider.getExercises() as Observable<any[]> this.exercisesList$ = (Observable<any[]>) this.workoutProvider.getExercises()

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

2 Comments

Hey, thank you for your reply, i tried the first one i got the following error:Type 'Observable<{}[]>' cannot be converted to type 'Observable<any[]>'.
I retried to become:this.exercisesList$ = this.workoutProvider.getExercises().valueChanges() as Observable <any[]> and i leave the this.exercicesList$ type as empty. and it work for me,, i don't now if it is the best practice because we should put type to this.exercices.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.