I have a probem with typing this line of code initialState[a][b].
I got this error:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ food: { pizza: boolean; chicken: boolean; }; transport: { bus: boolean; car: boolean; }; }'
function testTypescript(a: string, b: string) {
const initialState = {
food: {
pizza: false,
chicken: false,
},
transport: {
bus: false,
car: false,
},
};
const newData = !initialState[a][b]; // How can I type this line?
const newState = { ...initialState, [a]: newData };
return newState;
}