addInitializer
A method on a decorator's context that registers a function to run when each instance, or the class itself, is set up.
In more detail
It is used for work such as binding a method to its instance or registering the class somewhere, without editing the constructor. Initializers added from a method decorator run while each new instance is being constructed.
Related terms
- ClassMethodDecoratorContext — The typed object passed as the second argument to a standard method decorator, describing the method being decorated.
- decorator — A line starting with @ placed above a function or class that wraps it to add behaviour or information.
Taught in
- Literal Types: String, Number, Boolean Literals And const — Production TypeScript
- Modern Decorators: Stage 3 Standards And Class Metadata — Production TypeScript