最佳答案
如果我有一个类型的集合,看起来有点像这样:
type ValidValues = string | number | null
type ValidTypes = "text" | "time" | "unknown"
type Decorated = {
name?: string | null
type?: ValidTypes
value?: ValidValues
title: string
start: number
}
type Injected = {
extras: object
}
// overriding the types from Decorated
type Text = Decorated & Injected & {
name: string
type: "text"
value: string
}
我的实际代码还有更多内容,但这里展示了核心思想。我不想只有相信自己才能处理好类型之间的关系。我希望工具能够向我展示 Text
的类型定义在类型代数之后“计算”到什么程度。
因此,对于上面的示例,我希望在 Text
中指定的字段将覆盖以前在 Decorated
类型中进行的声明,并且假设的工具提示的输出应该向我显示如下内容:
{
name: string
type: "text"
value: string
title: string
start: number
extras: object
}
有什么方便的方法可以得到这些信息吗?