title: How to extract typescript mongoose/typegoose schema
body: <p>Here a declared schema</p>
  
  <pre class="lang-js prettyprint-override"><code>class AccountSchema;
  </code></pre>
  
  <p>Here a declared model</p>
  
  <pre class="lang-js prettyprint-override"><code>const AccountClass: Model&lt;AccountSchema &amp; Document&gt;;
  class Account extends AccountClass;
  </code></pre>
  
  <p>Why doesn't this work?</p>
  
  <pre class="lang-js prettyprint-override"><code>type ExtractSchema&lt;T extends Model&lt;Document&gt;&gt; = T extends Model&lt;infer D &amp; Document&gt; ? D : never;
  class Service&lt;T extends Model&lt;ExtractSchema&lt;T&gt; &amp; Document&gt;&gt; {
    public async getSchema(): ExtractSchema&lt;T&gt;;
  }
  class AccountService extends Service&lt;typeof Account&gt; {
    public test() {
     [ERROR: this.getSchema() returns never]
     this.getSchema()
    }
  }
  </code></pre>
  
  <p>What is the best way to extract out the schema using generics and is there any way to not include javascript getter and setter function, just plain field?</p>