Let's say I have this code:
export class ProductsListComponent {
@Output() onProductSelected: EventEmitter<Product>;
constructor() {
this.onProductSelected = new EventEmitter();
}
}
This is some example of EventEmitter
usage. I don't understand why first we declare onProductSelect explicitly stating that it is EventEmitter
that carries Product instance, and then we instantiate it with just new EventEmitter()
. Why not new EventEmitter<Product>()
?
I think that in C# I would have to go with the second way, because otherwise it wouldn't compile if EventEmitter
was generic.
Why doesn't TypeScript require that?
//EDIT:
Further clarification fo my question. What's the difference between:
@Output() onProductSelected: EventEmitter<Product>;
this.onProductSelected = new EventEmitter();
and
@Output() onProductSelected: EventEmitter;
this.onProductSelected = new EventEmitter();