Note: This post is a translated version of an article originally published on my personal blog. You can read the original Korean post here .
What Are Decorators?
Decorators are a metaprogramming syntax that lets you attach metadata β or extend behavior β on classes, methods, properties, and parameters without modifying the original code .
They're commonly used for:
Logging β track when methods are called
Validation β enforce constraints on class properties
Dependency Injection β wire up services automatically
Authorization β guard methods behind permission checks
Frameworks like Angular and NestJS lean heavily on decorators for all of the above.
Setting Up
First, enable decorators in your tsconfig.json :
{ "compilerOptions" : { "experimentalDecorators" : true } }
Enter fullscreen mode
Exit fullscreen mode
How Decorators Work
A decorator is just a function.β¦