ashfaq.p
ashfaq.p

Reputation: 5469

Assign type from key of a Interface

I have a interface:

interface IReceipt {
  payment: IPayment;
  details: string;
}

I have one component which takes payment as parameter:

const renderPayment = (props: {paymentInfo}) => {}

I need to define the type of paymentInfo as Payment. How can I use the IReceipt interface to assign type to paymentInfo

Something like {paymentInfo: IReceipt.payment}

Upvotes: 0

Views: 45

Answers (1)

Ashish
Ashish

Reputation: 4330

You can simply use:

paymentInfo: IReceipt['payment']

So you can simply write:

interface IReceipt {
    payment: IPayment;
    details: string;
}
const renderPayment = (props: {paymentInfo: IReceipt['payment']}) => {}

Upvotes: 4

Related Questions