Method and Accessor Decorators
A method decorator is a decorator function that is applied to a single method of a class. In a method decorator, you can observe, modify, or outright replace a method definition with one provided by the decorator. When a method decorator is called, it receives three parameters: target
, propertyKey
, and descriptor
:
target
: Since methods can be both instance methods (defined on instances of the class) and static methods (defined on the class itself),target
can be two different things. For instance methods, it's the prototype of the class. For static methods, it's the constructor function of the class. Usually, you type this parameter asany
.propertyKey
: This is the name of the method you're decorating.descriptor
: This is the property descriptor of the method you're decorating. ThePropertyDescriptor
interface is defined with this:interface PropertyDescriptor { configurable?: boolean; ...