title: How can I set a type of an Array so it is a keyof an interface?
body: <p>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:</p>
  <pre><code>interface MyStuff {
    key?: boolean;
  };
  
  var myThing: MyStuff = {};
  
  var MyStuffArray: /* magic code */ = [];
  
  MyStuffArray.push(&quot;key&quot;);
  
  for(var p of MyStuffArray) {
    myThing[p /* magic code */] = true;
  };
  </code></pre>
  <p>magic code being the area where I don't know what to put it as; because MyStuffArray can be only filled with keys from <code>MyStuff</code>.</p>
  <p>I have tried <code>myThing[p as keyof MyStuff] = true;</code> but I get an error: <code>Type 'boolean' is not assignable to type 'never'.</code></p>
  <p>This works: <code>(myThing as any)[p] = true</code>, however I feel like this is bad practice when you have to use the <code>any</code> keyword in any situation.</p>
  <p>If it helps: I do not want <code>MyStuffArray</code> to be filled with keys of <code>MyStuff</code>! I just want it so <code>MyStuffArray</code> <em>can</em> be filled with possible keys of <code>MyStuff</code>.</p>