我有一个界面:

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


我有一个将付款作为参数的组件:

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


我需要将PaymentInfo的类型定义为Payment。如何使用IReceipt接口将类型分配给paymentInfo

类似于{paymentInfo: IReceipt.payment}

最佳答案

您可以简单地使用:

paymentInfo: IReceipt['payment']


所以你可以简单地写:

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

07-22 18:52