From the course: TypeScript Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Creating a method decorator

Creating a method decorator - TypeScript Tutorial

From the course: TypeScript Essential Training

Creating a method decorator

- [Instructor] The best way to learn how to create a decorator, in my opinion, is with a method decorator. As I find it the most straightforward to understand and implement. As its name implies, a method decorator is a decorator that you apply to a method on line 19 and 29. Implementing a method decorator is as simple as writing a function that looks like this. This function gets executed at runtime and accepts three parameters. The first parameter target is the object that the decorator is being applied to. In the case of a method decorator, it is the instance of the object that the method belongs to. The second parameter property is the name of the property that the decorator is applied to. And finally, the third parameter descriptor is an object containing the current metadata about the property. Now, this descriptor object is actually the same for any property of any object, regular fields, getter setters, and…

Contents