• 欢迎光临~

[Typescript] 77. Easy - Unshift

开发技术 开发技术 2022-10-29 次浏览

Implement the type version of Array.unshift

For example:

type Result = Unshift<[1, 2], 0> // [0, 1, 2,]

 

/* _____________ Your Code Here _____________ */

type Unshift<T extends any[], U> = [U, ...T];


/* _____________ Test Cases _____________ */
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']>>,
]

 

程序员灯塔
转载请注明原文链接:[Typescript] 77. Easy - Unshift
喜欢 (0)