Reputation: 478
This syntax is from the Angular2 Hero tutorial.
getHeroes(): Promise<Hero[]> == getHeroes(): (Promise: Hero[]) ?
I am confused about the Promise<Hero[]>
part, in particular. Is it a way to represent multiple types at a time? What does the area between the <
and >
represent?
I am new to TypeScript and Angular2, but I want to know.
Upvotes: 0
Views: 97
Reputation: 3615
< SomeType > is a generic type in Typescript which means you can have a Class or Function with SubType of T and you can do anything to it without knowing its actual type in the function definition.
For example:
DoSomething<T> (input : T) : T {
// doing something on input
input += 2;
// return something with <T> type
return input;
}
see the Typescript handbook on generics
Upvotes: 3
Reputation: 10887
It's how generics are specified. A Promise can return a value of some type. The stuff inside the <>
specifies what this specific promise will return. You can get some more information here: https://www.typescriptlang.org/docs/handbook/generics.html
Upvotes: 1