I'm currently working with the following code snippet:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/catch';
import { map } from 'rxjs/operators';
interface SingleParamConstructor<T> {
new (response: any): T;
id: T;
}
@Injectable()
export class RestProvider<T> {
baseUrl:string = "http://localhost:3000";
constructor(private ctor: SingleParamConstructor<T>, private httpClient : HttpClient) { }
public getEntities<T>(): Observable<T[]> {
return this.httpClient
.get(this.baseUrl + '/products')
.pipe(map(entities => {
return entities.map((entity) => new this.ctor(entity));
}))
.catch((err) => Observable.throw(err));
}
}
Upon testing the code, I encounter the error
TS2339: Property 'map' does not exist on type 'Object'
.
The line causing the issue is:
return entities.map((entity) => new this.ctor(entity));
I am looking for help in understanding where I went wrong and how to successfully utilize the map function on entities
.