I find myself puzzled by the concept of typescript decorators and their purpose. It is said that they 'decorate' a class by attaching metadata to it. However, I am struggling to understand how this metadata is linked to an instance of the class. An example provided is in Angular 2.
@Component(
{
selector:...
}
)
export class foo { ... }
My current understanding is that Angular instantiates the foo class and somehow connects the instance with the arguments of the decorator so that it can offer services, directives, and templates. This functionality could potentially be achieved through class inheritance as well. If we have a Component class and have our component inherit from it, why couldn't Angular then pass those arguments during bootstrapping similar to how React handles props, eliminating the need for decorators in such cases?
class Component { ... } //assume members like selector, services, directives, etc..
class Foo extends Component { ... }
then you would instantiate it at bootstrap/runtime using this approach:
new Foo(ElementName, Directives, Services, etc..)
In React, this process was essentially happening behind the scenes. You extended a component and utilized its methods. When passing information upon instantiation, you would provide the props object.
I'm eager to gain further insight on this matter.