Registration metadata
Record property names for a registration or metadata system during class evaluation.
TypeScript · Decorator
A legacy property decorator is a runtime callback attached immediately before a class property. It receives the class constructor or prototype and the property name, so it can observe the declaration but cannot directly modify its descriptor.
A legacy property decorator is placed immediately before a class property. At runtime, TypeScript calls it with the class constructor for a static property or the class prototype for an instance property, plus the property name. It can observe the declaration, but it cannot directly replace or redefine the property because no descriptor is provided.
function propertyDecorator(target: Function | Object, propertyKey: string | symbol): void| Name | Type | Description |
|---|---|---|
target | Function | Object | The class constructor for a static property, or the class prototype for an instance property. |
propertyKey | string | symbol | The declared property name. |
The decorator callback returns void; the documented legacy property-decorator protocol does not provide a property descriptor to replace.
function logProperty(target: object, propertyKey: string | symbol): void {
console.log(String(propertyKey));
}
class User {
@logProperty
name = "Ada";
}
new User();The decorator observes the declared property name when the class is evaluated.
Record property names for a registration or metadata system during class evaluation.
Inspect whether specific instance or static properties are declared.
Build lightweight framework conventions around decorated class members.
DecoratorMethodDecoratorParameterDecoratorexperimentalDecoratorsClass Decorators