Angular2: using TypeScript generics
This post is an example of TypeScript generics usage, when writing an Angular2 application.
I'm working on a Stripe administration console. Stripe is a payment / subscription SaaS service that we use at OctoPerf.
I need to create pages that lists all our customers and plans. But Stripe returns paginated lists, and we need to do successive calls to their API to get the complete data. This mechanism is the same for both customers and plans lists. So we can factorise our code using generics in this particular case.
The generic model
The first step is to create a common interface for customers and plans. They share a String id.
export interface HasId {
id:string;
}