I'm pretty new to TS...I have this particular type:
export type MyType = {
high: {
age: number;
preview: [{ [key: string]: string | number }];
};
low: {
age: number;
preview: [{ [key: string]: string | number }];
};
medium: {
age: number;
preview: [{ [key: string]: string | number }];
};
};
I map through my Data object keys:
{Object.keys(data)
.map((item: string, key: number) => {
return (
data &&
data[item]?.preview && (
< component here >
)
);
})}
The data type is correct, but TS complains about "data[item]?.preview".
It says:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'MyType'. No index signature with a parameter of type 'string' was found on type 'MyType'.
Thanks