【发布时间】:2017-08-22 04:13:18
【问题描述】:
例如,我有
type Line = {
start: Point;
end: Point;
color: string; //'cyan'/'aquablue'/...
}
但现在我想在 Line 的基础上创建新的线型,以便将颜色存储为数字:
type HexColorLine = Point & {
color: number;
}
现在我希望 HexColorPoint 类型等于
{
start: Point;
end: Point;
color: number;
}
但它等于
{
start: Point;
end: Point;
color: string | number;
}
有没有办法覆盖但不扩展prop类型用一些简短的语法?我真的必须为此定义全新的类型吗?
【问题讨论】:
-
我很确定你不能像你试图做的那样覆盖。您可以改为声明一个不带颜色属性的
SimpleLine,然后将Line和HexColorLine声明为扩展SimpleLine?有什么原因我想念你不能这样做吗?
标签: typescript