When I make a GET call via HttpClient I want to pass back an array of the actual typed objects, vs. just a generic 'object', and so I tried to do this:
getExistingArsByLab(labId: number): Observable<EhsAssessmentAr[]> {
return this.http
.get<EhsAssessmentAr[]>(`${this.baseUrl}/ar?labId=${labId}`)
.pipe(
map(x => {
const ret = EhsAssessmentAr.fromJson(x);
ret.ar = this.sanitizer.sanitize(SecurityContext.HTML, ret.ar.replace(/\n/g, '<br/>'));
return ret;
})
)
}
That fromJson
method is declared to return the proper class, and I thought since I was sending this through map
that I'd get back an array. I'm REALLY new to RxJs so I'm sure I'm just doing something completely stupid there.
I'm getting theerror:
TS2322: Type 'Observable<EhsAssessmentAr>' is not assignable to type 'Observable<EhsAssessmentAr[]>`