interface Test {
name: "abcd" | "efgh" | "ijkl";
}
interface Human {
name: "abcd" | "efgh" | "ijkl"
}
我想与Human.name一起重用Test.name的类型,但是如何?有什么想法吗?
答案 0 :(得分:2)
将名称提取为联合类型
type NameTypes = "abcd" | "efgh" | "ijkl";
interface Test {
name: NameTypes;
}
interface Human {
name: NameTypes;
}
答案 1 :(得分:1)
这也应该起作用
interface Test {
name: "abcd" | "efgh" | "ijkl";
}
interface Human extends Test {
}