title: Type declaration for function that returns a class constructor
body: <p>I'm writing a TypeScript declaration file for a JavaScript game engine with a global structure and I don't quite know how to deal with this function that returns a class constructor. Here is a simplified version of the code:</p>
  
  <pre><code>var createScript = function(name) {
    var script = function(args) {
      this.app = args.app;
      this.entity = args.entity;
    }
    script._name = name
  
    return script;
  }
  </code></pre>
  
  <p>Users are meant to extend the <code>script</code> class constructor with their own code like this:</p>
  
  <pre><code>var MyScript = createScript('myScript');
  
  MyScript.someVar = 6;
  
  MyScript.prototype.update = function(dt) {
    // Game programming stuff
  }
  </code></pre>
  
  <p>What is the proper way to deal with the <code>createScript</code> function and <code>script</code> class constructor in my declaration file?</p>
  
  <p><strong>UPDATE</strong>
  I have updated my code example to show that users are also expected to extend the static side of the "class". The answers given so far, though awesome, don't seem to allow for that.</p>