[Typescript] 75. Easy - Push

Implement the generic version of Array.push

For example:

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

 

/* _____________ Your Code Here _____________ */

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


/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'

type cases = [
  Expect<Equal<Push<[], 1>, [1]>>,
  Expect<Equal<Push<[1, 2], '3'>, [1, 2, '3']>>,
  Expect<Equal<Push<['1', 2, '3'], boolean>, ['1', 2, '3', boolean]>>,
]

 

posted @ 2022-10-29 03:09  Zhentiw  阅读(13)  评论(0编辑  收藏  举报