Skip to main content

3062 - Shift

Answer TestCases

实现类型版本的 Array.shift

例如:

type Result = Shift<[3, 2, 1]> // [2, 1]

Solution

type Shift<T extends unknown[]> = T extends [unknown, ...infer Rest] ? Rest : []

通过 extendsinfer 组合,提取出数组出首元素之外的元素 Rest, 之后返回即可