Appearance
题目
实现类型版本的数组反转 Array.reverse
Array.reverse
例如:
type a = Reverse<["a", "b"]>; // ['b', 'a'] type b = Reverse<["a", "b", "c"]>; // ['c', 'b', 'a']
解答
type Reverse<T extends unknown[]> = T extends [...infer Rest, infer Last] ? [Last, ...Reverse<Rest>] : T;