We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ba0a20d commit 3f34952Copy full SHA for 3f34952
type-challenges/0055-hard-union-to-intersection/template.ts
@@ -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;
type-challenges/0055-hard-union-to-intersection/test-cases.ts
@@ -0,0 +1,11 @@
+import type { Equal, Expect } from "@type-challenges/utils";
+
+type cases = [
+ Expect<Equal<UnionToIntersection<"foo" | 42 | true>, "foo" & 42 & true>>,
+ Expect<
+ Equal<
7
+ UnionToIntersection<(() => "foo") | ((i: 42) => true)>,
8
+ (() => "foo") & ((i: 42) => true)
9
+ >
10
11
+];
0 commit comments