外观
约 144 字小于 1 分钟
2026-02-11
在类型系统里实现通用的 Array.push 。
Array.push
例如:
type Result = Push<[1, 2], '3'> // [1, 2, '3']
展开数组即可。
type Push<T extends any[], U> = [...T, U]
type cases = [ Expect<Equal<Push<[], 1>, [1]>>, Expect<Equal<Push<[1, 2], '3'>, [1, 2, '3']>>, Expect<Equal<Push<['1', 2, '3'], boolean>, ['1', 2, '3', boolean]>>, ]
可变元组 Variadic Tuple Types泛型 Generics泛型约束 Generics Constraints