title: How to extend a class with static methods?
body: <p>I want to extend my <code>UserModel.model</code> object with static functions. How can I do it?</p>
  <p>As you can see below, my <code>UserModel.model</code> is a mongoose model object, but I need to add methods to this object, the point is: I don't know how to write it. I can't use a <code>static{}</code> area like in Java/C# to execute static code, I don't find the way to write it. Do you?</p>
  <p>For instance, I want to add methods such as <code>exists</code>, <code>connect</code>, etc.</p>
  <pre><code>///&lt;reference path='../../lib/def/defLoader.d.ts'/&gt;
  
  import model = require('./Model');
  
  export module Models {
      export class UserModel extends model.Models.Model implements model.Models.IModel{
          /**
           * Name of the model.
           * MUST start by uppercase letter!
           */
          private static modelName: string = 'User';
  
          /**
           * Public readable schema as object.
           */
          public static schema: any = {
              /**
               * User Login
               */
              login: {
                  type: 'string',
                  minLength: 4,
                  maxLength: 16,
                  required: true,
                  notEmpty: true,
                  unique: true
              }
          };
  
          /**
           * Private schema as mongoose.Schema type.
           */
          private static _schema: mongoose.Schema = new mongoose.Schema(UserModel.schema);
  
          /**
           * The mongoose model that uses the mongoose schema.
           */
          public static model: mongoose.Model&lt;any&gt; = mongoose.model(UserModel.modelName, UserModel._schema);
  
  
  
          /**
           *************************************************************************************************
           *********************************** Public (Helpers) ********************************************
           *************************************************************************************************
           */
  
          /**
           * Name of the model.
           * MUST start by uppercase letter!
           */
          public modelName: string;
  
          /**
           * Contains the static value of the public schema as object.
           * It's a helper to always get the schema, from instance or static.
           */
          public schema: mongoose.Schema;
  
          /**
           * Contains the static value of the object used to manipulate an instance of the model.
           * It's a helper to always get the model, from instance or static.
           */
          public model: mongoose.Model&lt;any&gt;;
  
          /**
           * Use static values as instance values.
           */
          constructor(){
              super();
  
              // Use static values as instance values.
              this.modelName = UserModel.modelName;
              this.schema = UserModel.schema;
              this.model = UserModel.model;
          }
  
          /**
           *************************************************************************************************
           *********************************** Extended methods ********************************************
           *************************************************************************************************
           */
      }
  }
  </code></pre>