Property does not exist on type 'never' - on ngFor variable

Viewed 1314

When I'm trying to get responses from API, I use an ngFor for dynamically sorting my view. Here's the line of code:

  <agm-marker *ngFor="let httpResponses of response" [latitude]= "httpResponses.lat" [longitude]="httpResponses.lng"
        [agmFitBounds]="true">

To be more clear:

... *ngFor="let httpResponses of response" [latitude]= "httpResponses.lat" [longitude]="httpResponses.lng" ...

and it gives automatically the type of httpResponses as never. And because of that gives these errors below:

error TS2339: Property 'lng' does not exist on type 'never'.

error TS2339: Property 'lat' does not exist on type 'never'.

Can I declare any Typescript type on httpResponse in the Html file? The project works fine, I get the lat and lng values from httpResponses and display it, but however I constantly get these errors, I tried to declare type on httpResponses in component.ts file, it didn't change anything.

Thanks for any advice.

1 Answers

You should use bracket notation instead of dot notation for accessing property:

<agm-marker *ngFor="let httpResponses of response" [latitude]= "httpResponses['lat']" [longitude]="httpResponses['lng']"
        [agmFitBounds]="true">
Related