Shift
实现typescript 版本的Array.shift
举例:
type Result = Shift<[3, 2, 1]> // [2, 1]
// ============= Test Cases =============
import type { Equal, Expect } from './test-utils'
type cases = [
// @ts-expect-error
Shift<unknown>,
Expect<Equal<Shift<[]>, []>>,
Expect<Equal<Shift<[1]>, []>>,
Expect<Equal<Shift<[3, 2, 1]>, [2, 1]>>,
Expect<Equal<Shift<['a', 'b', 'c', 'd']>, ['b', 'c', 'd']>>
]
// ============= Your Code Here =============
type Shift<T extends any[]> =T extends [any, ...infer R] ? R : []
这道题应该和 Push Unshift 放一起。属于简单题呀。