wilded
7/3/2019 - 2:03 PM

Typescript Inheritance with passed Type

interface Item<T> { 
   id: T
   name: string
   price: number
} 

interface Product extends Item<number> {
   stock: number
}

interface Service extends Item<string> {}


const item1 = <Product> {}

item1.id = 1;
item1.name = "Juice";
item1.price = 5.00;

const item2 = <Service> {}

item2.id = 'ServiceABC';
item2.name = "Juice";
item2.price = 5.00;