0
I’m doing a function to return an object, and I’m saying that this function will return a type interface ICreditAndCreditCard
the inteface has been declared as follows.
export interface ICreditAndCreditCard extends ICredit {
creditCard: ICreditCard;
}
And the interface ICredit
that it extends this in the following manner.
export interface ICredit extends IPaymentBody {
customerAccount: {
value: string;
};
}
The problem that when I try to make my function return this object gets the following error in Typescript.
formatCreditAndCreditCard(credit): ICreditAndCreditCard {
return {
mode: credit?.mode ?? SHAPE_CREDIT_AND_CREDITCARD.mode,
name: credit?.name ?? SHAPE_CREDIT_AND_CREDITCARD.name,
customerAccount: {
value:
credit?.customerAccount?.value ?? SHAPE_CREDIT_AND_CREDITCARD.customerAccount.value,
},
creditCard: this.formatCredit(credit) ?? SHAPE_CREDIT_AND_CREDITCARD.creditCard,
};
}
The Interface IPaymentBody
export interface IPaymentBody {
mode: string;
name: string;
}
The function formatCreditCard()
and its kind of return
formatCreditCard(card): ICreditCard {
return {
mode: card?.mode ?? SHAPE_CREDITCARD.mode,
name: card?.name ?? SHAPE_CREDITCARD.name,
expiryMonth: card?.expiryMonth ?? SHAPE_CREDITCARD.expiryMonth,
expiryYear: card?.expiryYear ?? SHAPE_CREDITCARD.expiryYear,
type: {
code: card?.type?.code ?? SHAPE_CREDITCARD.type.code,
name: card?.type?.name ?? SHAPE_CREDITCARD.type.name,
},
number: card?.number ?? SHAPE_CREDITCARD.number,
};
}
I think there are missing data in your question. I haven’t been able to understand it to the point of try to give an answer. Maybe it’s worth it to [Edit]? :)
– Luiz Felipe
Can you enter the Ipaymentbody interface? And what kind of return
this.formatCredit
?– Samir Braga
@Samirbraga added
– Guilherme Rigotti
@Luizfelipe How could I improve ? I think now that I edited with more information became clearer,
– Guilherme Rigotti
@Guilhermerigotti, the passage
creditCard: this.formatCredit(credit)
shouldn’t becreditCard: this.formatCreditCard(credit)
?– Samir Braga
@Samirbraga Thanks man, that was right, fault my kkkkkkk
– Guilherme Rigotti