3060 - Unshift
原创2025/4/28小于 1 分钟
3060 - Unshift
by jiangshan (@jiangshanmeta) #简单 #array
题目
实现类型版本的 Array.unshift
。
例如:
type Result = Unshift<[1, 2], 0> // [0, 1, 2]
在 Github 上查看:https://tsch.js.org/3060/zh-CN
代码
/* _____________ 你的代码 _____________ */
type Unshift<T extends unknown[], U> = [U, ...T]
测试用例
/* _____________ 测试用例 _____________ */
import type { Equal, Expect } from '@type-challenges/utils'
type cases = [
Expect<Equal<Unshift<[], 1>, [1]>>,
Expect<Equal<Unshift<[1, 2], 0>, [0, 1, 2]>>,
Expect<Equal<Unshift<['1', 2, '3'], boolean>, [boolean, '1', 2, '3']>>,
]
相关链接
分享你的解答:https://tsch.js.org/3060/answer/zh-CN
查看解答:https://tsch.js.org/3060/solutions
更多题目:https://tsch.js.org/zh-CN