如果我有一个有点像这样的类型集合,只会更详细:
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
}
有什么方便的方法来获取这些信息吗?