Skip to content

Commit

Permalink
LastArrayElement: Avoid recursion (#647)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahrjarrett authored Jul 16, 2023
1 parent 3ebca46 commit 3475a02
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions source/last-array-element.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ typeof lastOf(array);
@category Array
@category Template literal
*/
export type LastArrayElement<ValueType extends readonly unknown[]> =
ValueType extends readonly [infer ElementType]
? ElementType
: ValueType extends readonly [infer _, ...infer Tail]
? LastArrayElement<Tail>
: ValueType extends ReadonlyArray<infer ElementType>
? ElementType
export type LastArrayElement<Elements extends readonly unknown[]>
= number extends Elements['length']
? Elements extends ReadonlyArray<infer Element>
? Element
: never
: Elements extends readonly [...any, infer Target]
? Target
: never;

0 comments on commit 3475a02

Please sign in to comment.