Skip to content

Commit

Permalink
feat(api): added the Last type
Browse files Browse the repository at this point in the history
  • Loading branch information
prescientmoon committed Jan 5, 2020
1 parent b48623f commit 44ae2f7
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/api/src/api/tuple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,12 @@ type ReverseReducer<T extends unknown[], C extends unknown[] = []> = {
* Reverses the order of elements from a tuple.
*/
export type Reverse<T extends unknown[]> = ReverseReducer<T>;

/**
* Extracts the last element from a tuple.
*/
export type Last<T extends unknown[]> = {
// We need to use this trick to get around typescripts recursive type limit.
0: Head<T>;
1: Last<Tail<T>>;
}[Tail<T> extends [] ? 0 : 1];

0 comments on commit 44ae2f7

Please sign in to comment.