I'm trying to invert an object's fields if a value exists, but I'm getting some error that I cannot decipher.
interface Control {
name1: boolean;
name2: boolean;
...
}
const values = ['name1', 'name2', ...];
const control: Control = {
name1: false,
name2: false,
...
}
for (const value of values) {
if ((value in control) {
control[value] = !control[value]; // error
}
}
Error message:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Control'.
No index signature with a parameter of type 'string' was found on type 'Control'.ts(7053)
However, the error goes away if I explicitly pass one of the object's fields, such as control['name1'].
Is there something I am not understanding?