Hello! I have a question that is a little more typescript centric than angular, but I was wondering what the best way to handle this situation is.
I have 2 interfaces, ProposalCoupons and LiveCoupons. They are very similar in structure.
interface ProposalCoupons {
reimb: number;
retail: number;
frequency: number;
percent: number;
}
interface LiveCoupons {
reimb_amount: number;
retail_amount: number;
percent: number;
}
These come from the API as an array of these objects.
I have a component that I want to be able to accept either of these, and do some aggregations using the data.
@Component({ ... })
class CommissionsComponent implements OnInit {
@Input() coupons: ProposalCoupons[] | LiveCoupons[];
ngOnInit() {
// use this.coupons and be able to access the data in a generic way, for example:
// this.coupons.reduce((acc, c) => acc += c.reimb * c.percent, 0);
}
}
How should I go about this? I looked into using class-transformer, but i'm not sure its able to do this sort of thing.