I'm creating a frontend-app with ts/react/redux. Im familiar with typed languages, but, it seems, not enough.
Situation: There is react component (we dont care about JSX here):
import React from 'react';
import './MathComponent.css';
interface MathData {
mathExpectation: number,
variance: number,
standardDeviation: number,
}
interface Props {
data: MathData,
}
export const MathComponent: React.FC<Props> = ({
data,
}) => {
const mathConvert = (num: number) => {
// some logic here
return number+1;
}
const myData = {...data};
const newData = Object.keys(data).map((key:string)=>{
myData[key] = mathConvert(myData[key]);
});
return (
...JSX
)
}
And here I have, as far as I understand, a common issue: myData[key] underline as an error with text:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Object'. No index signature with a parameter of type 'string' was found on type 'Object'.
I saw some similar questions, but didnt understand explaining.
So the idea is to iterate over all properties and mutate "myData" object using mathConvert-fnc on every property. I know, that mutate object is usually a bad approach, but I cant see here any other options.
I think, the main question: how to fix a type error, secondary: mabye there is a better approach to enumerate obj props and use my fnc on it?