跳到主要内容

联合类型转化为交叉类型

实现高级工具类型 UnionToIntersection<U>

例如

type I = UnionToIntersection<'foo' | 42 | true> // expected to be 'foo' & 42 & true
查看测试用例
import type { Equal, Expect } from '@type-challenges/utils'

type cases = [
  Expect<Equal<UnionToIntersection<'foo' | 42 | true>, 'foo' & 42 & true>>,
  Expect<Equal<UnionToIntersection<(() => 'foo') | ((i: 42) => true)>, (() => 'foo') & ((i: 42) => true)>>,
]