Created
July 8, 2024 18:05
-
-
Save himanshuteotia/26a9e063c24b12b73170c01095a55ba2 to your computer and use it in GitHub Desktop.
Decorators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Class Decorator | |
| A class decorator is applied to the entire class and has a single parameter. | |
| function classDecorator(target: Function) { | |
| // target is the constructor function of the class | |
| } | |
| Method Decorator | |
| A method decorator is applied to a method within a class and has three parameters. | |
| function methodDecorator(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) { | |
| // target is the prototype of the class | |
| // propertyKey is the name of the method | |
| // descriptor is the property descriptor for the method | |
| } | |
| Accessor Decorator | |
| An accessor decorator is applied to a getter or setter and has the same three parameters as a method decorator. | |
| function accessorDecorator(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) { | |
| // target is the prototype of the class | |
| // propertyKey is the name of the accessor (getter or setter) | |
| // descriptor is the property descriptor for the accessor | |
| } | |
| Property Decorator | |
| A property decorator is applied to a property within a class and has two parameters. | |
| function propertyDecorator(target: Object, propertyKey: string | symbol) { | |
| // target is the prototype of the class (for instance properties) | |
| // or the constructor function (for static properties) | |
| // propertyKey is the name of the property | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment