Having difficulties updating an Object's property based on a dynamic variable. Even after searching for answers on stackoverflow, I haven't been able 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
-------------
....
}
}
An issue arises - "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'."
Attempted using:
export interface RawData {
products: keyof Products
}
But then received an error on data.products[type].totals
Error message: "Property 'bikes' does not exist on type 'string'."