I am facing an issue with looping through a TypeScript array. The following methods are being used:
getNotification(evt: string, rowIndex: number) {
console.log("Production order: law has changed to " + evt + " " + rowIndex);
var select = document.getElementsByName("ProductId-" + rowIndex);
this.removeOptions(select);
if ((evt != null) && (evt != "")) {
let productsByLaw: IProduct[];
productsByLaw = this.products.filter(x => x.lawId == +evt);
for (let product in productsByLaw) {
select.options[select.options.length] = new Option(product.name, product.productid);
}
}
}
removeOptions(selectbox : any) {
var i;
for (i = selectbox.options.length - 1; i >= 0; i--) {
selectbox.remove(i);
}
}
I am unsure as to why the error
Option(product.name, product.productid)
is being thrown:
Error TS2339 (TS) Property 'name' does not exist on type 'string'.
Error TS2339 (TS) Property 'productid' does not exist on type 'string'.
Why is product
being recognized as a string instead of type IProduct
?