title: Map JSON object into TypeScript Object
body: <p>I am returning an array of objects from server using AJAX JQuery, an example </p>
  
  <pre><code>[{"Name":"Name1","ResultSet":[{"Id": 1,"Name":"Name1"}, {"Id": 2,"Name":"Name2"}]},{"Name": "Name11", "ResultSet": [{"Id": 11, "Name": "Name11"}, {"Id": 22, "Name": "Name22"}]}]
  </code></pre>
  
  <p>Also, I have the following TypeScript object I want to map </p>
  
  <pre><code>interface IResult {
     name: string;
     resultSet: any;
  }
  
  export class Result implements IResult {
      constructor(public name: string, public resultSet: any) { }
  }
  </code></pre>
  
  <p>The way I am processing the results,</p>
  
  <pre><code>dataService.execute(function (results) {
      $(results).each(function (index, element) {
          console.log(element.Name);
              $.each(element.ResultSet, function (key, value) {
                  $.each(value, function (key, value) {
                      console.log(key + ' - ' + value);
                  });
              });
          });
      });
  </code></pre>
  
  <p>Inside VS 2013, the compiler complains that:</p>
  
  <pre><code>The property 'Name' does not exist on value of type 'Element'.
  </code></pre>
  
  <p>Is there a way to map the returned collection of objects to an array of TS Result objects?</p>
  
  <p>Thanks</p>
  
  <p><strong>UPDATE</strong>
  I ended up looping as follows:</p>
  
  <pre><code>var result = &lt;Array&lt;IResult&gt;&gt;results;
  
  $.each(result, function (index, item) {
        // item is Result instance
        // item.name
        console.log(item.name);
  
        // item.resulSet
        $.each(item.resultSet, function (key, val) {
              // val is single Object (one result)
              $.each(val, function (k, v) {
                    // k,v =&gt; key/value for each property on result
                      console.log(k + ' - ' + v);
              });
        });
  </code></pre>
  
  <p>});</p>