title: How to reduce javascript object to only contain properties from interface
body: <p>When using typescript a declared interface could look like this:</p>
  
  <pre><code>interface MyInterface {
    test: string;
  }
  </code></pre>
  
  <p>And an implementation with extra property could be like this:</p>
  
  <pre><code>class MyTest implements MyInterface {
    test: string;
    newTest: string;
  }
  </code></pre>
  
  <p><strong>Example</strong> (here the variable 'reduced' still contain the property 'newTest'):</p>
  
  <pre><code>var test: MyTest = {test: "hello", newTest: "world"}
  
  var reduced: MyInterface = test; // something clever is needed
  </code></pre>
  
  <p><strong>Question</strong></p>
  
  <p>In a general way, how can you make the 'reduced' variable to only contain the properties declared in the 'MyInterface' interface. </p>
  
  <p><strong>Why</strong></p>
  
  <p>The problem occur when trying to use the 'reduced' variable with angular.toJson before sending it to a rest service - the toJson method transforms the newTest variable, even if it's not accessible on the instance during compile, and this makes the rest service not accept the json since it has properties that shouldn't be there. </p>