amazingCarrotSoup amazingCarrotSoup - 2 months ago 116
TypeScript Question

types typescript inside for loop local loop variable not respecting type

this.venuelist has type Venue

venuelist:Venue[] = [];

has the property
on it.

I have the following for loop

for(let venue in this.venuelist){
let remove = false;
if(this.filters.neighborhood != ''){
if(venue.neighborhood != this.filters.neighborhood){
remove = true;

calling venue.neighborhood called in the second `if statement` is not working

the error is: Property 'neighborhood' does not exist on type 'string.

for why? Why must it do this. Why can't it play nice? How do I make it place nice?

Answer Source
for(let venue in this.venuelist){} doesn't iterate over the array items, it iterates over the keys of the object passed in. You should use for...of

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download