title: Mongoose static methods in typescript
body: <p>I use <code>mongoose</code> in <code>nestjs</code> application. On static method I stuck. I create my static method in separate file <code>message.methods.ts</code>:</p>
  
  <pre class="lang-js prettyprint-override"><code>import { Schema } from 'mongoose';
  
  import { MessageForResponseDTO } from 'modules/room/dto/message-for-response.dto';
  
  /*
    Types
  */
  export type getMessageForResponseFunction = (
    _id: Schema.Types.ObjectId,
  ) =&gt; MessageForResponseDTO;
  
  /*
    Methods
  */
  const getMessageForResponse: getMessageForResponseFunction = function(
    _id: Schema.Types.ObjectId,
  ) {
    return this.findOne({ _id }).populate('user');
  };
  
  /*
    Export
  */
  export const messageStaticMethods = { getMessageForResponse };
  </code></pre>
  
  <p>And import it into my schema in <code>message.schema.ts</code>:</p>
  
  <pre><code>import { Schema } from 'mongoose';
  
  import { messageStaticMethods } from './message.methods';
  
  const MessageSchema = new Schema(
    {
      room: {
        type: Schema.Types.ObjectId,
        ref: 'Room',
        required: true,
      },
      user: {
        type: Schema.Types.ObjectId,
        ref: 'User',
        required: true,
      },
      message: {
        type: String,
        required: true,
        trim: true,
      },
      usersInMessage: [
        {
          type: Schema.Types.ObjectId,
          ref: 'User',
          required: false,
        },
      ],
    },
    { timestamps: true },
  );
  
  MessageSchema.statics = messageStaticMethods;
  
  export default MessageSchema;
  </code></pre>
  
  <p>Also, for call my schema, I create <code>message.model.ts</code>:</p>
  
  <pre><code>import { Document, Schema } from 'mongoose';
  
  export interface MessageModel extends Document {
    readonly room: Schema.Types.ObjectId;
    readonly user: Schema.Types.ObjectId;
    readonly message: string;
    readonly usersInMessage: Schema.Types.ObjectId[];
  
    // dates
    createdAt?: Date;
    updatedAt?: Date;
  }
  </code></pre>
  
  <p>The problem is, when I trying to use my static method <code>const getMessageForResponse = await this.messageModel.getMessageForResponseFunction(_id);</code> I got an error:</p>
  
  <pre><code>Property 'getMessageForResponseFunction' does not exist on type 'Model&lt;MessageModel, {}&gt;'.
  </code></pre>
  
  <p>How and where I should declare this method to call it as static? Thank you!</p>