title: How to do runtime type casting in TypeScript?
body: <p>Currently I'm working on a typescript project and I'm really enjoying the type inference that TypeScript brings to the table. However - when getting objects from HTTP calls - I can cast them to the desired type, get code completion and call functions on them <em>compile time</em>, but those result in errors <em>runtime</em></p>
  
  <p><strong>Example:</strong></p>
  
  <pre><code>class Person{
      name: string;
  
      public giveName() {
          return this.name;
      }
  
      constructor(json: any) {
          this.name = json.name;
      }
  }
  
  var somejson = { 'name' : 'John' }; // Typically from AJAX call
  var john = &lt;Person&gt;(somejson);      // The cast
  
  console.log(john.name);       // 'John'
  console.log(john.giveName()); // 'undefined is not a function'
  </code></pre>
  
  <p>Although this compiles nicely - and intellisense suggests me to use the function, it gives a runtime exception. A solution for this could be:</p>
  
  <pre><code>var somejson = { 'name' : 'Ann' };
  var ann = new Person(somejson);
  
  console.log(ann.name);        // 'Ann'
  console.log(ann.giveName());  // 'Ann'
  </code></pre>
  
  <p>But that will require me to create constructors for all my types. In paticular, when dealing with tree-like types and/or with collections coming in from the AJAX-call, one would have to loop through all the items and new-up an instance for each.</p>
  
  <p><strong>So my question:</strong> is there a more elegant way to do this? That is, cast to a type and have the prototypical functions available for it immediately?</p>