title: Angular 5 prevent adding props to class
body: <p>I have this class</p>
  
  <pre><code>export class Alpha {
       propAlpha?:string;
  
       constructor(){
       }
  
       setProp(key: string, value: string) {
          this[key] = value;
       }
  
  }
  </code></pre>
  
  <p>Some rest call gives me an object (response) like this:</p>
  
  <pre><code>{
      propAlpha: "foo",
      _someUnwanted: "bar"
  }
  </code></pre>
  
  <p>I need to push only valid props of this object into Alpha, so I did</p>
  
  <pre><code>let myAlpha = new Alpha();
  _.each(Object.keys(response), key =&gt; {
      validProp(response[key]) &amp;&amp; myAlpha.setProp(key, response[key]);
      /**
       * validProp() checks if value matches some criteria.
       * So even if "propAlpha" is in "Alpha" it may be 
       * excluded for some other reason!
       */
  });
  </code></pre>
  
  <p>the problem is that <code>_someUnwanted</code> is added to my class.
  How can I prevent that?</p>
  
  <p>I'd need to check which keys are in Alpha..</p>
  
  <p>maybe like this?</p>
  
  <pre><code>if(key in myAlpha) {
     myAlpha.setProp(key, response[key]);
  }
  </code></pre>