Problem with Typescript interfaces

Asked

Viewed 45 times

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.

Erro


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,
    };
  }
  • 1

    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]? :)

  • Can you enter the Ipaymentbody interface? And what kind of return this.formatCredit?

  • @Samirbraga added

  • @Luizfelipe How could I improve ? I think now that I edited with more information became clearer,

  • @Guilhermerigotti, the passage creditCard: this.formatCredit(credit) shouldn’t be creditCard: this.formatCreditCard(credit)?

  • @Samirbraga Thanks man, that was right, fault my kkkkkkk

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.