title: How to define custom query helper in mongoose model with typescript?
body: <p>I want to define custom query helper using  <a href="https://mongoosejs.com/docs/guide.html#query-helpers" rel="nofollow noreferrer">query helper api</a> . 
  Here the example:</p>
  
  <pre><code>// models/article.ts
  
  import { Document, Schema, Model, model } from 'mongoose';
  
  interface IArticle extends Document {
     name: string;
  }
  
  interface IArticleModel extends Model&lt;IArticle&gt; {
     someStaticMethod(): Promise&lt;any&gt;;
  }
  
  const ArticleSchema = new Schema( { name: String } )
  
  ArticleSchema.query.byName = function(name) {
      return this.find({ name })
  }
  
  export default model&lt;IArticle, IArticleModel&gt;('Article', ArticleSchema);
  
  
  
  // routes/article.ts
  import ArticleModel from '../models/article.ts'
  
  router.get('/articles, (req, res) =&gt; {
      ArticleModel.find().byName('example')
  })
  </code></pre>
  
  <p>Typescript complains about <code>byName</code> method when I chain it with defaults.<br>
  I can put it in <code>IArticleModel</code> interface but in that case I could only call it from model.<br>
  Where should I put the definition of this method to use it in chainable way?</p>