代码拉取完成,页面将自动刷新
/*
55 - Union to Intersection
-------
by Zheeeng (@zheeeng) #困难 #utils #infer
### 题目
> 由谷歌自动翻译,欢迎 PR 改进翻译质量。
实现高级util类型`UnionToIntersection<U>`
例如
```ts
type I = Union2Intersection<'foo' | 42 | true> // expected to be 'foo' & 42 & true
```
> 在 Github 上查看:https://tsch.js.org/55/zh-CN
*/
/* _____________ 你的代码 _____________ */
type ToUnionOfFunction<T> = T extends any ? (x: T) => any : never;
type UnionToIntersection<U> = ToUnionOfFunction<U> extends (a: infer U) => any ? U : never
/* _____________ 测试用例 _____________ */
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)>>,
]
/* _____________ 下一步 _____________ */
/*
> 分享你的解答:https://tsch.js.org/55/answer/zh-CN
> 查看解答:https://tsch.js.org/55/solutions
> 更多题目:https://tsch.js.org/zh-CN
*/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。