• 欢迎光临~

[Typescript] 75. Easy - Push

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

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]>>,
]

 

程序员灯塔
转载请注明原文链接:[Typescript] 75. Easy - Push
喜欢 (0)
违法和不良信息举报电话:022-22558618 举报邮箱:dljd@tidljd.com