This is quite hard for me to explain, as I'm not sure what to call it. I have a interface and I want to set some properties using an array element as such:
interface MyStuff {
key?: boolean;
};
var myThing: MyStuff = {};
var MyStuffArray: /* magic code */ = [];
MyStuffArray.push("key");
for(var p of MyStuffArray) {
myThing[p /* magic code */] = true;
};
magic code being the area where I don't know what to put it as; because MyStuffArray can be only filled with keys from MyStuff.
I have tried myThing[p as keyof MyStuff] = true; but I get an error: Type 'boolean' is not assignable to type 'never'.
This works: (myThing as any)[p] = true, however I feel like this is bad practice when you have to use the any keyword in any situation.
If it helps: I do not want MyStuffArray to be filled with keys of MyStuff! I just want it so MyStuffArray can be filled with possible keys of MyStuff.