← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

TypeScript Decorators

TypeScript 4.0 Advanced
debt(d5/e3/b7/t7)
d5 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'specialist tool catches it' (d5). The detection_hints list TypeScript compiler and ESLint. Missing experimentalDecorators causes a TS compiler error (which is caught), but mixing legacy and TC39 standard decorators or forgetting reflect-metadata import at the entry point can produce runtime failures that the compiler won't always catch clearly. The code_pattern notes mixing legacy and standard decorators in the same project, which requires careful tooling configuration to surface — landing at d5.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix is essentially a tsconfig flag change (experimentalDecorators: true) or adding a reflect-metadata import — both are small, localised changes. However, if a project has mixed legacy and TC39 standard decorators, untangling them touches multiple files. The common cases lean toward e3, with mixed-decorator scenarios pushing slightly higher but not reaching e5 consistently.

b7 Burden Structural debt — long-term weight of choosing wrong

Closest to 'strong gravitational pull' (b7). Decorators are the foundational abstraction for major frameworks (NestJS, Angular, TypeORM) as noted in why_it_matters. Once a codebase adopts decorator-heavy frameworks, the decorator model shapes every service, entity, and component definition. The incompatibility between legacy and TC39 standard decorators (TS 5.0+) means this choice reverberates across the entire project's tsconfig, dependency versions, and framework compatibility — every future change is shaped by which decorator model was chosen.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7). The misconception field explicitly states that developers familiar with Python decorators will guess wrong — Python decorators are simple function wrappers, while TypeScript decorators have a specific API, rely on reflect-metadata, and run at class definition time (not instantiation). Additionally, the legacy vs. TC39 standard decorator incompatibility contradicts what a developer might expect from a newer TypeScript version. These are documented gotchas that contradict behavior from analogous concepts in other languages, placing this at t7.

About DEBT scoring →

Also Known As

decorators @Injectable @Entity class decorator

TL;DR

Metadata annotations on classes, methods, and properties — used in NestJS, Angular, TypeORM, and class-validator to attach behaviour declaratively.

Explanation

TypeScript decorators (TC39 Stage 3 in 2024) annotate classes and members with @Decorator syntax. Class decorators modify or replace the class. Method decorators wrap methods. Property decorators define metadata on properties. Parameter decorators annotate constructor/method parameters. Decorator metadata: reflect-metadata stores type information accessed at runtime, enabling dependency injection (NestJS @Injectable), ORM mapping (TypeORM @Entity, @Column), and validation (class-validator @IsEmail). TypeScript 5.0 implements the TC39 decorator proposal; legacy decorators (experimentalDecorators) differ.

Common Misconception

TypeScript decorators are the same as Python decorators — Python decorators are functions wrapping functions at definition time; TypeScript decorators have a specific API and use reflect-metadata for rich type information.

Why It Matters

NestJS, Angular, and TypeORM depend on decorators for their core abstractions — understanding decorators explains how @Injectable creates services and how @Column maps properties to database columns.

Common Mistakes

  • Not enabling emitDecoratorMetadata and experimentalDecorators in tsconfig for legacy decorators.
  • Forgetting to import reflect-metadata at the entry point for metadata decorators.
  • Using legacy decorators (experimentalDecorators) with TS 5.0 new decorators — they are incompatible.
  • Decorators that have side effects during class definition — decorators run at class definition time, not instantiation.

Code Examples

✗ Vulnerable
// Manual DI wiring without decorators — verbose:
const userService = new UserService(new UserRepository(new Database()));
const orderService = new OrderService(userService, new OrderRepository(new Database()));
// Every constructor dependency must be manually wired
✓ Fixed
// NestJS decorators — declarative DI:
@Injectable()
export class UserService {
    constructor(private readonly userRepo: UserRepository) {}
}

@Entity('users')
export class User {
    @PrimaryGeneratedColumn()
    id: number;

    @Column({ unique: true })
    @IsEmail()
    email: string;
}

@Controller('users')
export class UserController {
    constructor(private readonly userService: UserService) {}

    @Get(':id')
    findOne(@Param('id') id: number): Promise<User> {
        return this.userService.findById(id);
    }
}

Added 16 Mar 2026
Edited 22 Mar 2026
Views 46
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 1 ping S 1 ping M 2 pings T 1 ping W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 2 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Perplexity 8 Amazonbot 8 Ahrefs 4 Scrapy 4 Google 3 Bing 3 Unknown AI 2 Claude 2 ChatGPT 2 Meta AI 1
crawler 32 crawler_json 5
DEV INTEL Tools & Severity
🟢 Low ⚙ Fix effort: Medium
⚡ Quick Fix
Enable experimentalDecorators: true in tsconfig for legacy decorators; note TypeScript 5.0 added standard Stage 3 decorators — the APIs differ between legacy and standard
📦 Applies To
typescript 4.0 web cli
🔗 Prerequisites
🔍 Detection Hints
Legacy @decorator syntax without experimentalDecorators; mixing legacy and TC39 standard decorators in same project
Auto-detectable: ✓ Yes typescript eslint
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: High Context: Class Tests: Update


✓ schema.org compliant