title: Mongoose typescript model creation with multiple connections
body: <p>I'm trying to create a model while using multiple connections (<a href="https://mongoosejs.com/docs/connections.html#multiple_connections" rel="nofollow noreferrer">following the docs</a>) but I get the following error:</p>
  <pre><code>TS2345: Argument of type 'Schema&lt;Document&lt;any&gt;, Model&lt;Document&lt;any&gt;&gt;&gt;' is not assignable to parameter of
  type 'Schema&lt;UserInterface, UserModelInterface&gt;'.
  Types of property 'methods' are incompatible.
  ... (a bunch of 'is not assignable - is missing the following properties' errors follow) ...
  </code></pre>
  <p>My code looks like this:</p>
  <p><sub><strong>database.ts</strong></sub></p>
  <pre class="lang-js prettyprint-override"><code>import mongoose from &quot;mongoose&quot;;
  
  // const mongo = mongoose.connection(process.env.DB_URI!, {
  const mongo = mongoose.createConnection(process.env.DB_URI!, {
      useUnifiedTopology: true,
      useNewUrlParser: true,
      useFindAndModify: false,
      useCreateIndex: true
  })
  
  export default mongo
  </code></pre>
  <p><sub><strong>UserModel.ts</strong></sub></p>
  <pre class="lang-js prettyprint-override"><code>import mongoose, {Model} from 'mongoose';
  import bcrypt from 'bcrypt'
  import database from &quot;../database&quot;;
  
  interface UserDocumentInterface extends mongoose.Document {
      firstname: string
      lastname: string
      ...
  }
      
  interface UserInterface extends UserDocumentInterface {
      // Instance methods
      hashPassword(password: string): Promise&lt;string&gt;
      ...
  }
      
  export interface UserModelInterface extends Model&lt;UserInterface&gt; {
      // Static methods
      // Currently empty
  }
  
  const UserSchema = new mongoose.Schema({
      firstname: {
          type: String,
          required: true,
          trim: true
      },
      lastname: {
          type: String,
          required: true,
          index: true,
          trim: true,
      },
      ...
  })
  
  // Methods definitions
  UserSchema.methods.hashPassword = async function(password) {
      return await bcrypt.hash(password, 10);
  }
  ...
  
  // const User: UserModelInterface = mongoose.model&lt;UserInterface, UserModelInterface&gt;('User', UserSchema)
  const User = database.model&lt;UserInterface, UserModelInterface&gt;('User', UserSchema)
  export default User
  
  </code></pre>
  <p>The error appears on <code>UserSchema</code>  in <code>const User = database.model&lt;UserInterface, UserModelInterface&gt;('User', UserSchema)</code></p>
  <p>What I don't understand is why this line works without issues</p>
  <pre class="lang-js prettyprint-override"><code>const User: UserModelInterface = mongoose.model&lt;UserInterface, UserModelInterface&gt;('User', UserSchema)
  </code></pre>
  <p>but this one throws an error</p>
  <pre class="lang-js prettyprint-override"><code>const User = database.model&lt;UserInterface, UserModelInterface&gt;('User', UserSchema)
  </code></pre>
  <p>when the only thing that changes is the connection type, <code>mongoose.createConnection()</code> as opposed to mongoose default connection</p>