Skip to content

Instantly share code, notes, and snippets.

@ragmha
Created November 26, 2018 14:04
Show Gist options
  • Save ragmha/0b2afdd498b3ea909ff2e43d9eedc8ed to your computer and use it in GitHub Desktop.
Save ragmha/0b2afdd498b3ea909ff2e43d9eedc8ed to your computer and use it in GitHub Desktop.
class Pizza {
constructor(private name: string, private price: number) {}
}
class List<T> {
private list: T[] = [];
addItem(item: T): void {
this.list.push(item);
}
getList(): T[] {
return this.list;
}
}
const list = new List<Pizza>();
list.addItem(new Pizza("Pepperoni", 15));
const pizzas = list.getList();
class Coupon {
constructor(private name: string) {}
}
const anotherList = new List<Coupon>();
anotherList.addItem(new Coupon("PIZZA25"));
const cupons = anotherList.getList();
console.log(pizzas);
console.log(cupons);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment