Typescript 类型级别过滤
我需要从联合中过滤地图类型
type B = FilterMap<string | { a: 1 }> // { a: 1 }
type C = FilterMap<boolean | { b:2 }> // { b:2 }
type D = FilterMap<number | { c: 3 }> // { c: 3 }
这可能吗?
I need to filter a Map type from union
type B = FilterMap<string | { a: 1 }> // { a: 1 }
type C = FilterMap<boolean | { b:2 }> // { b:2 }
type D = FilterMap<number | { c: 3 }> // { c: 3 }
is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用预定义类型
Extract;
,从联合中提取任何对象类型:游乐场链接
You can use the predefined type
Extract<T, U>
, to extract any object type from a union:Playground Link