Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Decorators (Experimental) – Clas | TypeScript Mastery lesson | BraveProgrammer
  1. Courses
  2. /
  3. TypeScript Mastery

Lesson 20 of 56

·Typescript

Decorators (Experimental) – Class & Method

20 minutes

Course progress36%

Enabling Decorators

Add to tsconfig.json:

"experimentalDecorators": true,
"emitDecoratorMetadata": true

Class Decorator Example

function sealed(constructor: Function) {
  Object.seal(constructor);
  Object.seal(constructor.prototype);
}

@sealed
class Service {
  // …
}

Method Decorator – Logging

function log(target: any, propertyKey: string, descriptor: PropertyDescriptor) {
  const original = descriptor.value;
  descriptor.value = function (...args: any[]) {
    console.log(`Calling ${propertyKey} with`, args);
    return original.apply(this, args);
  };
}

class MathOps {
  @log
  add(a: number, b: number) {
    return a + b;
  }
}

Warning

Decorators are stage‑2 proposal; they may change. Use them primarily in frameworks (Angular, NestJS).
Make it stickPractice what you've learned1 quiz · 3 practical tests · Optional activities from TypeScript MasteryBrowse activities
Previous lessonAccessors (get/set) & Readonly PropertiesContinue to lesson 21Modules – ES6 Imports/Exports & NamespacesBack to TypeScript Mastery curriculum