如果我有一个看起来有点像这样的类型集合,只会更详细:
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
}
Run Code Online (Sandbox Code Playgroud)
我的实际代码还有更多内容,但这显示了核心思想。我不想必须相信自己才能使类型之间的关系恰到好处。Text在所有类型代数之后,我想要工具向我展示“评估”的类型定义。
因此,对于上面的示例,我希望 中指定的字段Text将覆盖该Decorated类型中先前的声明,并且我假设的工具提示的输出(我希望)会显示如下内容:
{
name: string
type: "text"
value: string
title: string …Run Code Online (Sandbox Code Playgroud)