I'm having trouble when I try to update an Object's property based on a dynamic variable. I've checked a few more answers on stackoverflow but couldn't manage to find a solution.
export interface Bikes {
totals: Array<number>;
}
interface Products {
cars: Cars;
bikes: Bikes;
}
export interface RawData {
products: Products
}
demo( data: RawData ) {
// data.products contains both "cars" and "bikes" properties.
for (var type in data.products) {
for (var product in data.products[type].totals) {// <-- error here
-------------
....
}
}
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Products'. No index signature with a parameter of type 'string' was found on type 'Products'.
I've also tried using:
export interface RawData {
products: keyof Products
}
And then the error appears on data.products[type].totals
Property 'bikes' does not exist on type 'string'.
for-inloop? And what is the definition of theCarsandBikestypes?