Pop
题目
Github: Pop
实现一个通用Pop<T>
,它接受一个数组T
,并返回一个由数组T的前length-1
项以相同的顺序组成的数组。
type arr1 = ['a', 'b', 'c', 'd']
type arr2 = [3, 2, 1]
type re1 = Pop<arr1> // expected to be ['a', 'b', 'c']
type re2 = Pop<arr2> // expected to be [3, 2]
::: detailer Answer
type Pop<T extends any[]> = T extends [...infer R, any] ? R : T
:::