TypeScript Support
To get started with Mongoose in TypeScript, you need to:
- Create an interface representing a document in MongoDB.
- Create a Model.
- .
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 instance methods 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 .