Typescript is awesome! Mongoose is popular.

Thanks to , we now have typescript definitions for mongoose, however getting both to talk can still be tricky.

There are a few tools out there to help us merge mongoose with typescript such as Typegoose and ts-mongoose, but, for one reason or another you may not want to use these tools and roll out without extra dependencies.

This post is a knowledge summary for what I believe to be a good way to build APIs with mongoose and typescript. I assume that the reader is already familiar with both individually.

Table of contents
Keeping a typescript interface and a mongoose schema in sync 🔗
Informing mongoose about our user type
Adding typesafety for Populate and Select
Including statics and instance methods
Splitting the user model into backend and frontend representations
Conclusion

#mongoose #mongodb #typescript #nodejs #model #schema

How To Link Mongoose And Typescript for a Single Source of Truth | Hacker Noon
4.55 GEEK