<p>The code is,</p>
<pre><code>const userSchema = new mongoose.Schema({
  email: {
    type: String,
    required: true,
  },
  password: {
    type: String,
    required: true,
  },
});

console.log(userSchema);

userSchema.statics.build = (user: UserAttrs) =&gt; {
  return new User(user);
};

userSchema.pre(&quot;save&quot;, async function (next) {
  if (this.isModified(&quot;password&quot;)) {
    const hashed = await Password.toHash(this.get(&quot;password&quot;));
    this.set(&quot;password&quot;, hashed);
  }
  next();
});
</code></pre>
<p>Now, the error I'm running into is,</p>
<pre><code>[auth] &gt; auth@1.0.0 start /app
[auth] &gt; ts-node-dev src/index.ts
[auth]
[auth] [INFO] 12:46:59 ts-node-dev ver. 1.0.0 (using ts-node ver. 9.0.0, typescript ver. 3.9.7)
[auth] Compilation error in /app/src/models/user.ts
[auth] [ERROR] 12:47:04 ⨯ Unable to compile TypeScript:
[auth] src/models/user.ts(37,12): error TS2551: Property 'statics' does not exist on type 'Schema'. Did you mean 'static'?
[auth] src/models/user.ts(46,3): error TS2554: Expected 1 arguments, but got 0.
</code></pre>
<p>The statics property does exist in the schema object and it does show when I console.log(userSchema). I think it has something to do with kubernetes and skaffold. Any idea how to fix this problem ??</p>

<p>I think this could help</p>
<p>First you have to create 3 interfaces.</p>
<pre><code>interface UserAttrs {
  email: string;
  password: string;
}

interface UserModel extends mongoose.Model&lt;UserDoc&gt; {
  build(attrs: UserAttrs): UserDoc;
}

interface UserDoc extends mongoose.Document {
  email: string;
  password: string; 
}
</code></pre>
<p>Then in your schema's middleware you have to declare the type of the variables that you're using</p>
<pre><code>userSchema.pre(&quot;save&quot;, async function (this: UserDoc, next: any) {
  if (this.isModified(&quot;password&quot;)) {
    const hashed = await Password.toHash(this.get(&quot;password&quot;));
    this.set(&quot;password&quot;, hashed);
  }
  next();
});

const User = mongoose.model&lt;UserDoc, UserModel&gt;('User', userSchema);
</code></pre>
<p><a href="https://github.com/Automattic/mongoose/issues/6725" rel="nofollow noreferrer">Related issue that I found</a></p>
