Skip to content

Commit 3f34952

Browse files
committed
0055-hard-union-to-intersection
1 parent ba0a20d commit 3f34952

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// 参考 https://github.com/type-challenges/type-challenges/issues/1051
2+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
3+
arg: infer I
4+
) => void
5+
? I
6+
: never;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { Equal, Expect } from "@type-challenges/utils";
2+
3+
type cases = [
4+
Expect<Equal<UnionToIntersection<"foo" | 42 | true>, "foo" & 42 & true>>,
5+
Expect<
6+
Equal<
7+
UnionToIntersection<(() => "foo") | ((i: 42) => true)>,
8+
(() => "foo") & ((i: 42) => true)
9+
>
10+
>
11+
];

0 commit comments

Comments
 (0)