Open FrankKai opened 2 years ago
TypeScript类型体操,核心思想是 通过类型生成新的类型! 记录一下type-challenges的题解,以及解题思路。
仓库地址:https://github.com/type-challenges/type-challenges/blob/main/README.zh-CN.md
infer / (...args: any) => infer P https://github.com/type-challenges/type-challenges/issues/11520
infer / (...args: any) => infer P
keyof / extends / in https://github.com/type-challenges/type-challenges/issues/11545
keyof / extends / in
keyof / extends / in https://github.com/type-challenges/type-challenges/issues/11021
readonly https://github.com/type-challenges/type-challenges/issues/11104
readonly
T[number] / extends / infer / never https://github.com/type-challenges/type-challenges/issues/11408
T[number] / extends / infer / never
extends / readonly / in / T[number] https://github.com/type-challenges/type-challenges/issues/11105
extends / readonly / in / T[number]
泛型组合 / Record / 伪return this https://github.com/type-challenges/type-challenges/issues/12073
泛型组合 / Record / 伪return this
extends / never / T[0] https://github.com/type-challenges/type-challenges/issues/11107
extends / never / T[0]
...T / T['length'] / infer https://github.com/type-challenges/type-challenges/issues/11586
...T / T['length'] / infer
infer / ...T https://github.com/type-challenges/type-challenges/issues/11595
infer / ...T
extends / readonly / T['length'] https://github.com/type-challenges/type-challenges/issues/11109
extends / readonly / T['length']
extends / never https://github.com/type-challenges/type-challenges/issues/11111
extends / never
infer / 递归 / Promise<T> https://github.com/type-challenges/type-challenges/issues/11747
infer / 递归 / Promise<T>
extends boolean / extends true https://github.com/type-challenges/type-challenges/issues/11404
extends boolean / extends true
...T 解构 https://github.com/type-challenges/type-challenges/issues/11423
...T 解构
keyof / in https://github.com/type-challenges/type-challenges/issues/11589
keyof / in
infer / ...T 解构 / 递归 https://github.com/type-challenges/type-challenges/issues/11534
infer / ...T 解构 / 递归
...T 解构 https://github.com/type-challenges/type-challenges/issues/11527
...T 解构 https://github.com/type-challenges/type-challenges/issues/11529
infer https://github.com/type-challenges/type-challenges/issues/11539
infer
TypeScript类型体操,核心思想是 通过类型生成新的类型! 记录一下type-challenges的题解,以及解题思路。
仓库地址:https://github.com/type-challenges/type-challenges/blob/main/README.zh-CN.md
2 - 获取函数返回类型
infer / (...args: any) => infer P
https://github.com/type-challenges/type-challenges/issues/115203 - 实现 Omit
keyof / extends / in
https://github.com/type-challenges/type-challenges/issues/115454 - 实现 Pick
keyof / extends / in
https://github.com/type-challenges/type-challenges/issues/110217 - 实现 Readonly
readonly
https://github.com/type-challenges/type-challenges/issues/1110410 - 元组转合集
T[number] / extends / infer / never
https://github.com/type-challenges/type-challenges/issues/1140811 - 元组转换为对象
extends / readonly / in / T[number]
https://github.com/type-challenges/type-challenges/issues/1110512 - 可串联构造器
泛型组合 / Record / 伪return this
https://github.com/type-challenges/type-challenges/issues/1207314 - 第一个元素
extends / never / T[0]
https://github.com/type-challenges/type-challenges/issues/1110715 - 最后一个元素
...T / T['length'] / infer
https://github.com/type-challenges/type-challenges/issues/1158616 - 出堆
infer / ...T
https://github.com/type-challenges/type-challenges/issues/1159518 - 获取元组长度
extends / readonly / T['length']
https://github.com/type-challenges/type-challenges/issues/1110943 - Exclude
extends / never
https://github.com/type-challenges/type-challenges/issues/11111189 - Awaited
infer / 递归 / Promise<T>
https://github.com/type-challenges/type-challenges/issues/11747268 - If
extends boolean / extends true
https://github.com/type-challenges/type-challenges/issues/11404533 - Concat
...T 解构
https://github.com/type-challenges/type-challenges/issues/11423599 - Merge
keyof / in
https://github.com/type-challenges/type-challenges/issues/11589898 - Includes
infer / ...T 解构 / 递归
https://github.com/type-challenges/type-challenges/issues/115343057 - Push
...T 解构
https://github.com/type-challenges/type-challenges/issues/115273060 - Unshift
...T 解构
https://github.com/type-challenges/type-challenges/issues/115293312 - Parameters
infer
https://github.com/type-challenges/type-challenges/issues/11539