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
]
type Equal<T, U> =
(<P>(x: P) => P extends T ? 1: 2) extends
(<P>(x: P) => P extends U ? 1: 2)
? true
: false
/* _____________ Test Cases _____________ */
import type { 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]>>,
]
标签:12,_____________,Typescript,extends,Expect,Easy,Push,type From: https://www.cnblogs.com/Answer1215/p/16653983.html