Enhancing Express.js Requests with TypeScript: Adding User Objects and More
Express JS has been one of the best Node JS framework for creating backend(server side) part of any application. It is fast and easy to learn and implement. It is soo scalable and reliable that it is being used in small and as well as in large application. I loved using it along with typescript too because it enhances the code quality and readability. In addition, you also get the advantage of better code completion and intellisense when using modern text editors like Visual Studio Code. One of the most useful concept of Typescript is “Declaration Merging” . Declaration Merging allows you to merge two or more distinct declaration or types declared with the same name into a single definition. This concept allows you to attach your own custom property onto another Typescript interface type. Lets take a look at Express middleware. The above code is an Express middleware that is used to ensure that a user is authenticated...