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....
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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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 ofif(!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....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.