题目
中文
实现类型版本的数组反转 Array.reverse
例如:
type a = Reverse<['a', 'b']>; // ['b', 'a']
type b = Reverse<['a', 'b', 'c']>; // ['c', 'b', 'a']
English
Implement the type version of Array.reverse
For example:
type a = Reverse<['a', 'b']>; // ['b', 'a']
type b = Reverse<['a', 'b', 'c']>; // ['c', 'b', 'a']
答案
type Reverse<T extends any[]> = T extends [infer L, ...infer R]
? [...Reverse<R>, L]
: T;
标签:...,Typescript,Reverse,体操,type,infer,reverse
From: https://www.cnblogs.com/laggage/p/type-challenge-reverse.html