Menu

Build a Logger and Validator with TypeScript Decorators (Like NestJS)
πŸ–ΌοΈ

Build a Logger and Validator with TypeScript Decorators (Like NestJS)

DEV CommunityΒ·Malloc72PΒ·7 months ago
#awl2CNMO
#webdev#typescript#decorator#nestjs#software
Reading 0:00
15s threshold

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.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.