I want to set each value in an object using Typescript, but I can't seem to get it to work in any elegant way. This is what I have:
const myObject = {
keyA: '',
keyB: '',
};
for (const key in myObject) {
myObject[key] = 'something';
}
But I get the typescript error:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type
{ keyA: string; keyB: string; }
.
No index signature with a parameter of type 'string' was found on type{ keyA: string; keyB: string; }
. TS7053
Shouldn't Typescript know that key must be a key of myObject?