Type 'Observable<Object>' is not assignable to type 'Observable<IUser[]>' Type 'Observable<Object>' is not assignable to type 'Observable<IUser[]>' javascript javascript

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);}