I have class to which I set property values in a for loop. One of the properties is object, class respectively.
But after the for loop ends, this property loses its type and it is cast to simple Object. Why?
public setAttributes(data:any):void {
for (var name in data) {
if (this.hasOwnProperty(name)) {
switch (name) {
case 'restaurant':
this.restaurant = new Restaurant(data.restaurant);
console.log(this.restaurant); //log 1
default:
this[name] = data[name];
}
}
}
console.log(this.restaurant); //log 2
this.restaurant = new Restaurant(data['restaurant']);
console.log(this.restaurant); //log 3
}
Calling function with
this.setAttributes({
title: 'test',
restaurant: {
title: 'restaurant test'
}
})
results in
Restaurant {title: 'restaurant test'} //log 1
Object {title: 'restaurant test'} //log 2
Restaurant {title: 'restaurant test'} //log 3
Why the second log (//log 2) has type Object but not Restaurant?
Thanks for your replies.