【发布时间】:2019-04-03 12:23:14
【问题描述】:
我想在 typescript 中使用两个不同的接口创建接口属性。这可能吗?
interface IPayload1 {
id: string;
name: string;
}
interface IPayload2 {
id: string;
price: number;
}
interface Demo {
// Can this be possible?
payload: IPayload1 | IPayload2;
}
【问题讨论】:
-
payload?: IPayload1 | IPayload2将使其成为可选 -
对不起,可选词,我不想要可选参数,payload是必需的。
-
您的代码看起来不错。什么不工作?
标签: typescript interface typescript-typings