Push
约 141 字小于 1 分钟
2026-02-11
题目
在类型系统里实现通用的 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]>>,
]