Having the following shared
export class DataStorageService {
constructor(private http: HttpClient) {}
fetchAll(dataType: string) {
let apiEndpoint = environment.config.urlLogin + '/api/' + dataType;
return this.http.get(apiEndpoint);
}
and using it here
export class InvoiceListComponent implements OnInit {
invoices: Invoice[] = [];
constructor(private ds: DataStorageService) {
}
ngOnInit(): void {
this.fetchInvoices();
}
fetchInvoices() {
this.ds.fetchAll('invoices').subscribe((responseData) => {
if (responseData.hasOwnProperty('hydra:member')) {
//reaching here
// but this throws compile error
this.invoices = responseData['hydra:member'];
}
})
}
I get the following compile error with Angular 12:
Element implicitly has an 'any' type because expression of type '"hydra:member"' can't be used to index type 'Object'. Property 'hydra:member' does not exist on type 'Object'.
Honestly I do not understand at all why this is showing up. I mean I even reach the positive check whether this property exists?
{}, per angular.io/guide/http#requesting-a-typed-response.