How to write definition of type in function argument which is one of object properties with same type?
For example I have object:
type Article = {
name: string;
quantity: number;
priceNet: number;
priceGross: number;
};
and want to write function which summarise price depending on price type property:
function summarise(article: Article, priceTypeProperty: NeededProperty) {
return article[priceTypeProperty] * article.quantity;
}
How definition of NeededProperty
should look like to ensure typescript that it's one of Article properties priceNet
or priceGross
and it is number
type?