title: Combined class and interface type
body: <p>In Javascript (under WScript or HTA), I would write the following pattern:</p>
  
  <pre><code>var fso = new ActiveXObject('Scripting.FileSystemObject');
  var ext = fso.GetExtensionName('C:\test.txt');    //returns 'txt'
  var badResult = fso.NonExistentMethod();          //raises a runtime error
  </code></pre>
  
  <p>Using TypeScript, I can declare an interface which will prevent this sort of error:</p>
  
  <pre><code>module Scripting {
      export interface FileSystemObject {
          GetExtensionName(path: string): string,
          GetParentFolderName(path: string): string
      }
  }
  
  var fso: Scripting.FileSystemObject = new ActiveXObject('Scripting.FileSystemObject');
  var ext = fso.GetExtensionName('C:\test.txt'); //ext is recognized as a string
  //var badResult = fso.NonExistentMethod();     //will not compile
  </code></pre>
  
  <p>However, I would like to initialize the <code>fso</code> variable like this:</p>
  
  <pre><code>var fso = new Scripting.FileSystemObject();
  </code></pre>
  
  <p>and have the type system automatically deduce that the type of <code>fso</code> is the interface <code>Scripting.FileSystemObject</code>.</p>
  
  <p>Can this be done?</p>
  
  <hr>
  
  <p>1) I can't add the constructor to the interface, because the interface is only the shape of the object, not its implementation.</p>
  
  <hr>
  
  <p>2) I thought about creating an internal interface, and extending the interface with a class and a constructor:</p>
  
  <pre><code>module Scripting {
      interface Internal {
          GetExtensionName(path: string): string;
          GetParentFolderName(path: string): string;
      }
  
      export class FileSystemObject extends Internal {
          constructor() {
              return new ActiveXObject('Scripting.FileSystemObject');
          }
      }
  }
  </code></pre>
  
  <p>but constructors cannot be added to an extending class without a call to the base type constructor, which an interface does not have.</p>
  
  <hr>
  
  <p>3) I cannot have a single <code>declared</code> class, because the constructor is still an implementation and cannot be written into a <code>declared</code> class, which is an ambient context.</p>