The code returns the error Type 'Subscription' is missing the following properties from type 'ToDo[]': length, pop, push, concat, and 26 more.
This is usually caused by the return observable not being set as an array. In my case the return type is an array but this error keeps breaking my app. Despite working previously.
toDoList: ToDo[];
this.usertodo = this.getUserTodo(this._userId);
getUserTodo(id: number): ToDo[] {
return this.DataService.apiGetUserTodo(id).subscribe(
todo => {
this.toDoList = todo;
}
);
}
// IN DATA SERVICE
apiGetUserTodo(id: number): Observable<ToDo[]> {
const url = `${this.APIurl}/users/${id}/todos`;
return this.http.get<ToDo[]>(url).pipe(
tap(data => console.log('USER ' + JSON.stringify(data)))
);
}
This should be error free however this message comes up
ERROR in src/app/todo/todo.component.ts:28:8 - error TS2740: Type 'Subscription' is missing the following properties from type 'ToDo[]': length, pop, push, concat, and 26 more.