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 property decorator

Creating a property decorator - TypeScript Tutorial

From the course: TypeScript Essential Training

Creating a property decorator

- [Instructor] So far in this chapter, I've shown you how to create method decorators and class decorators. In this video, I'm going to show you about the third kind of decorator, the property decorator. As its name implies, property decorators are decorators that are applied to properties of a class, like the context property of our contact repository example, and you apply a decorator to a property the same way you apply one to a class or a method like this. Here, I'm applying a decorator called auditable, which I'll create in a minute, to the contacts property. The implementation of this decorator will log a message to the console anytime the value of this property has changed. Since methods are just properties of a class that happen to be functions, the definition of a property decorator looks very much like a method decorator, a function that accepts two parameters, the target and the property name. And just like the…

Contents