【发布时间】:2023-03-23 22:20:01
【问题描述】:
假设我有一个界面:
// I get this from an external library so I have no control over it
interface Balloon {
diameter: number;
color: "red" | "blue" | "green";
}
我想创建自己的界面,如下所示:
interface Shirt {
size: "m" | "l" | "xl";
color: "red" | "blue" | "green";
}
我的问题是是否可以从 Balloon 中“取出”颜色部分并将其注入到 Shirt 中,所以我得到了这样的东西:
interface Shirt {
size: "m" | "l" | "xl";
color: Balloon.color; // I know this is wrong but it is to illustrate what I want to achieve
}
【问题讨论】:
-
当然。
color: Balloon['color'] -
@ritaj 您可以将其发布为答案
-
是的,非常简单优雅的解决方案和非常快速的响应,谢谢!
标签: typescript