Skip to content

Commit

Permalink
feat(api): added the ValN type
Browse files Browse the repository at this point in the history
  • Loading branch information
prescientmoon committed Jan 5, 2020
1 parent e0f0e90 commit b48623f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/api/src/api/keyval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,29 @@ export type Val8<
H extends Keys7<T, A, B, C, D, E, F, G>
> = Val7<T, A, B, C, D, E, F, G>[H];

/**
* Internal reducer for ValN.
*
* @internal
*
* @param T The structure to get the values from.
* @param C The current key.
* @param R The remaining keys
*/
type ValNReducer<T, C, R extends unknown[]> = C extends keyof T
? {
0: T[C];
1: ValNReducer<T[C], Head<R>, Tail<R>>;
}[R extends [] ? 0 : 1]
: never;

/**
* Generalised version of Val1-Val7
*/
export type ValN<T, L extends unknown[]> = L extends []
? T
: ValNReducer<T, Head<L>, Tail<L>>;

/**
* Utilities for constructing types with nested keys removed.
*/
Expand Down

0 comments on commit b48623f

Please sign in to comment.