Vite
Vuepress
Rspack / Rsbuild
外观
132字小于1分钟
2022-12-01
题目
Github: Push
在类型系统里实现通用的 Array.push 。
Array.push
type Result = Push<[1, 2], '3'> // [1, 2, '3']
通过 泛型约束T 为数组类型,对 T 进行展开到新数组中,并将 U 合并到新数组的末尾。
T
U
type Push<T extends any[], U> = [...T, U]
可变元组 Variadic Tuple Types泛型 Generics泛型约束 Generics Constraints