我是 Typescript 的新手,并陷入了这个问题。所以,我有一个类型定义为:
type MainType = Node & {
id: string;
name: string;
notifications: number
}
Run Code Online (Sandbox Code Playgroud)
我想要一个不包含Node类型的类型。
//Expected type
{
id: string;
name: string;
notifications: number
}
// I tried using Exclude, but it returns never
type SecondaryType = Exclude<MainType, Node>
//I tried using Omit, but that doesn't allow me to pass Node
type SecondaryType = Omit<MainType, Node>
Run Code Online (Sandbox Code Playgroud)
小智 5
您需要省略类型中的所有键Node:
type SecondaryType = Omit<MainType, keyof Node>
Run Code Online (Sandbox Code Playgroud)
检查这个游乐场链接
| 归档时间: |
|
| 查看次数: |
1619 次 |
| 最近记录: |