联合类型转交叉类型

作者:xie392地址:https://v.douyin.com/ieQGrasM/更新时间:2024-12-21

案例代码

1
type UnionToIntersction<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never
2
3
type test = { a: string } | { b: number } | { c: boolean }
4
5
type test2 = UnionToIntersction<test> // { a: string } & { b: number } & { c: boolean }