shrimpdrake shrimpdrake - 1 year ago 69
TypeScript Question

<> syntax in Typescript Angular2

I'm new to Angular2 and I don't understand that <> syntax :

example 1 ( from ) :

let mockService = <HeroService> {getHeroes: () => expectedHeroes }

example 2 ( from )

deleteRequest = new EventEmitter<Hero>();

Any help or reference to a comprehensive answer is appreciated.

Answer Source

<HeroService> {getHeroes: () => expectedHeroes } corresponds to a cast / type assertion to the HeroService class. The returned object will follow the structure of this class.

new EventEmitter<Hero>(); is a way to parametrize the EventEmitter class (generics) to tell that it'll handle elements of type Hero. In the case of the EventEmitter class (see, it ensures that objects used as a parameter of the emit method must be of type Hero.

See the following links for more details: