Have you ever wondered how to take an existing type and simply add a few properties to it without having to re-declare the whole thing?
Well, that's what you can do by using intersection types which is represented by the use of &
.
The syntax is rather simple. See an example below:
A simple type:
interface product {
product: IProduct & {
productAmount: number;
itemPrice: number;
totalPrice: number }
}
And in case you want it be arrays instead it would look something like this:
interface product {
product: IProduct[] & {
productAmount: number;
itemPrice: number;
totalPrice: number }[]
}