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']
/* _____________ Your Code Here _____________ */
type Reverse<T> = T extends [...infer H, infer T] ? [T, ...Reverse<H>] : [];
/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'
type cases = [
Expect<Equal<Reverse<[]>, []>>,
Expect<Equal<Reverse<['a', 'b']>, ['b', 'a']>>,
Expect<Equal<Reverse<['a', 'b', 'c']>, ['c', 'b', 'a']>>,
]
标签:Typescript,Reverse,_____________,55,Medium,Expect,type,infer From: https://www.cnblogs.com/Answer1215/p/16803738.html