TypeScript Support

    To get started with Mongoose in TypeScript, you need to:

    1. Create an interface representing a document in MongoDB.
    2. Create a Model.
    3. Connect to MongoDB.

    Alternatively, your document interface can extend Mongoose’s class. Many Mongoose TypeScript codebases use the below approach.

    We recommend your document interface contain the properties defined in your schema and line up with what your documents look like in MongoDB. Although you can add to your document interface, we do not recommend doing so.

    Now that you’ve seen the basics of how to use Mongoose in TypeScript, let’s take a look at statics in TypeScript.