首页 > 其他分享 >[Typescript] 77. Easy - Unshift

[Typescript] 77. Easy - Unshift

时间:2022-10-29 03:22:30浏览次数:79  
标签:Typescript _____________ Unshift 77 Expect Easy type

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,_____________,Unshift,77,Expect,Easy,type
From: https://www.cnblogs.com/Answer1215/p/16837965.html

相关文章