title: Try to compare Password using mongoose and bcrypt in typescript
body: <p>I am getting the following error in line 40:</p>
  <pre class="lang-js prettyprint-override"><code>    bcrypt.compare(candidatePassword, this.password, function (err, isMatch) {
                                        ~~~~~~~~~~~~~
  </code></pre>
  <blockquote>
  <p>Argument of type 'Function' is not assignable to parameter of type 'string'.ts(2345)</p>
  </blockquote>
  <p>According to the IUser it should be as string and i have no idea why ts means it is a function.</p>
  <p>The complete file:</p>
  <pre class="lang-js prettyprint-override"><code>import { Schema, Document } from 'mongoose';
  import bcrypt from 'bcrypt';
  
  const salt: number = 12;
  
  const UserSchema: Schema&lt;IUser&gt; = new Schema({
      email: {
          type: String,
          required: true,
          unique: true,
      },
      name: {
          type: String,
          required: true,
          minlength: 3,
          maxlength: 32,
      },
      password: {
          type: String,
          required: true,
      },
  });
  
  // * Hash the password befor it is beeing saved to the database
  UserSchema.pre('save', function (next: (err: Error | null) =&gt; void) {
      // * Make sure you don't hash the hash
      if (!this.isModified('password')) {
          return next(null);
      }
      bcrypt.hash(this.password, salt, (err: Error, hash: String) =&gt; {
          if (err) return next(err);
          this.password = hash;
      });
  });
  
  UserSchema.methods.comparePasswords = function (
      candidatePassword: String,
      next: (err: Error | null, same: Boolean | null) =&gt; void,
  ) {
      bcrypt.compare(candidatePassword, this.password, function (err, isMatch) {
          if (err) {
              return next(err, null);
          }
          next(null, isMatch);
      });
  };
  
  export interface IUser extends Document {
      email: String;
      name: String;
      password: String;
  }
  
  </code></pre>