Type 'Observable<Object>' is not assignable to type 'Observable<IUser[]>'
There are two ways to do this, and it depends on which version of RxJS / Angular that you are using. Here are the two ways to do it depending on your versions:
// Using RxJS v4 / Angular v2-4. I assume that you're using the HttpModule...import 'rxjs/add/operator/map';public getUsers(url: string): Observable<IUser[]> { return this._http.get(url) .map((response: Response) => <IUser[]>response.json());}// Using RxJS v5 / Angular 5+ (at the moment). I assume that you're using the HttpClientModule, as the HttpModule was deprecated in Angular v4.public getUsers(url: string): Observable<IUser[]> { return this._http.get<IUser[]>(url);}
Typical, that 5 mins after I post, I find a solution.
Trick was to cast the .get
function in the service the same as the type on the getUsers
function as below:
public getUsers(url: string): Observable<IUser[]> { return this._http.get<IUser[]>(url); }
Hope this helps other people out as well
in my case the below worked
getUsers(): Observable<User[]> { return <Observable<User[]>> this.http.get(this.pathAPI + 'user', super.header()) .pipe(catchError(super.handleError)); }
I am using Angular 6