I want to have a array of Payment(s) for every Rent, but I want to be able to pass one or more Payments through the constructor...
I am getting error that says: "Type '(Payment | Payment[])[]' is not assignable..." on the second appearance of this.payment
Code:
class Rent {
payments: Payment[]
date: Date
constructor(date: Date, payment:Payment|Payment[]) {
this.date = date
if(payment instanceof Array){
this.payments = payment
}else{
this.payments = [payment]
}
}
PS: I am aware that I could always use [Payment] while creating one, but I like to have options