Skip to content

Commit

Permalink
feat(api): added the WithoutN type
Browse files Browse the repository at this point in the history
  • Loading branch information
prescientmoon committed Jan 5, 2020
1 parent f6c333a commit 0d13af5
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/api/src/api/keyval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,31 @@ export type Without8<
H extends Keys7<T, A, B, C, D, E, F, G>
> = Without<T, A> & { [id in A]: Without7<Val1<T, A>, B, C, D, E, F, G, H> };

/**
* Internal reducer used as a building block for WithoutN.
*
* @internal
*
* @param T The structure to remove keys from.
* @param C The current key.
* @param R The remaining keys.
*/
type WithoutNReducer<T, C, R extends unknown[]> = C extends keyof T
? {
0: Without<T, C>;
1: Without<T, C> & Record<C, WithoutNReducer<T[C], Head<R>, Tail<R>>>;
}[R extends [] ? 0 : 1]
: never;

/**
* Generalised version of Without0-Without8.
*/
export type WithoutN<T, P extends unknown[]> = WithoutNReducer<
T,
Head<P>,
Tail<P>
>;

/**
* Utilities for replacing types of nested keys.
*/
Expand Down

0 comments on commit 0d13af5

Please sign in to comment.