DEV Community

Discussion on: First Look at Lambda Powertools TypeScript

 
elthrasher profile image
Matt Morgan

I can appreciate that perspective. I like using decorators (and I liked annotations in Java) because they reduce boilerplate code. There are definitely pros and cons and one thing to consider is the developers and teams that will need to interact with the code.

I've used decorators in express apps for years and I'm a big fan of putting something like @Authorized on a route instead of if(!sessionNotValid(req)) throw Error(401) or something like that. Remains to be seen whether I'll like using decorators in Lambda as much, but I can think of a lot more boilerplate that could be rolled up....

Thread Thread
 
gerardolima profile image
Gerardo Lima

In Node applications, I don't use decorators and neither do I use if ... statements to check for authorization inside handlers -- that's what's the middlewares are for...

Nevertheless, at the end of the day, it's a matter of preference. Just keep in mind that support for decorators in typescript is not stable and you might have your build pipeline constrained to the tools that support it and you may encounter some issues when upgrading tsc compiler, for example.