typescript 实现数组push unshift pop shift

  type arrPush = [ ...args:T, a:U] extends [...args : infer G] ? G : never
  type newArr = arrPush<[1,3,4], 5>
  let g:newArr = [1,3,4,5]




  type arr = [1,2,3,4]
  type $unshift =  [U,...T]
  type newArr = $unshift
  let a:newArr = [5,1,2,3,4]


  type a = [1,2,3]
  type arrPop = [...args: T] extends [...args: infer G, a: infer C] ? G : never
  type c = arrPop
  let ar1 : c= [1,2]


  type arr = [1,2,3,4]
  type $shift =  [...args : T] extends  [b: infer Y,...args : infer G ] ? G : never
  type newArr = $shift
  let a: newArr = [2,3,4]

你可能感兴趣的:(typescript,javascript,前端)