-
-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): add Path0-8, PathVal1-8, DeepPath types
- Loading branch information
1 parent
6df0110
commit 0c76108
Showing
3 changed files
with
218 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
import { NumOrString } from "./prim"; | ||
import type { | ||
Keys, | ||
Keys1, | ||
Keys2, | ||
Keys3, | ||
Keys4, | ||
Keys5, | ||
Keys6, | ||
Keys7, | ||
Val1, | ||
Val2, | ||
Val3, | ||
Val4, | ||
Val5, | ||
Val6, | ||
Val7, | ||
Val8, | ||
} from "./keyval"; | ||
|
||
/** | ||
* Lookup path for nested data structures. | ||
*/ | ||
export type Path = PropertyKey | PropertyKey[]; | ||
|
||
export type Path0 = readonly []; | ||
|
||
export type Path1<T, A> = A extends Keys<T> ? readonly [A] : never; | ||
|
||
export type Path2<T, A, B> = A extends Keys<T> | ||
? B extends Keys1<T, A> | ||
? readonly [A, B] | ||
: never | ||
: never; | ||
|
||
export type Path3<T, A, B, C> = A extends Keys<T> | ||
? B extends Keys1<T, A> | ||
? C extends Keys2<T, A, B> | ||
? readonly [A, B, C] | ||
: never | ||
: never | ||
: never; | ||
|
||
export type Path4<T, A, B, C, D> = A extends Keys<T> | ||
? B extends Keys1<T, A> | ||
? C extends Keys2<T, A, B> | ||
? D extends Keys3<T, A, B, C> | ||
? readonly [A, B, C, D] | ||
: never | ||
: never | ||
: never | ||
: never; | ||
|
||
export type Path5<T, A, B, C, D, E> = A extends Keys<T> | ||
? B extends Keys1<T, A> | ||
? C extends Keys2<T, A, B> | ||
? D extends Keys3<T, A, B, C> | ||
? E extends Keys4<T, A, B, C, D> | ||
? readonly [A, B, C, D, E] | ||
: never | ||
: never | ||
: never | ||
: never | ||
: never; | ||
|
||
export type Path6<T, A, B, C, D, E, F> = A extends Keys<T> | ||
? B extends Keys1<T, A> | ||
? C extends Keys2<T, A, B> | ||
? D extends Keys3<T, A, B, C> | ||
? E extends Keys4<T, A, B, C, D> | ||
? F extends Keys5<T, A, B, C, D, E> | ||
? readonly [A, B, C, D, E, F] | ||
: never | ||
: never | ||
: never | ||
: never | ||
: never | ||
: never; | ||
|
||
export type Path7<T, A, B, C, D, E, F, G> = A extends Keys<T> | ||
? B extends Keys1<T, A> | ||
? C extends Keys2<T, A, B> | ||
? D extends Keys3<T, A, B, C> | ||
? E extends Keys4<T, A, B, C, D> | ||
? F extends Keys5<T, A, B, C, D, E> | ||
? G extends Keys6<T, A, B, C, D, E, F> | ||
? readonly [A, B, C, D, E, F, G] | ||
: never | ||
: never | ||
: never | ||
: never | ||
: never | ||
: never | ||
: never; | ||
|
||
export type Path8<T, A, B, C, D, E, F, G, H> = A extends Keys<T> | ||
? B extends Keys1<T, A> | ||
? C extends Keys2<T, A, B> | ||
? D extends Keys3<T, A, B, C> | ||
? E extends Keys4<T, A, B, C, D> | ||
? F extends Keys5<T, A, B, C, D, E> | ||
? G extends Keys6<T, A, B, C, D, E, F> | ||
? H extends Keys7<T, A, B, C, D, E, F, G> | ||
? readonly [A, B, C, D, E, F, G, H] | ||
: never | ||
: never | ||
: never | ||
: never | ||
: never | ||
: never | ||
: never | ||
: never; | ||
|
||
// prettier-ignore | ||
export type DeepPath<T, A, B, C, D, E, F, G, H> = A extends Keys<T> | ||
? B extends Keys1<T, A> | ||
? C extends Keys2<T, A, B> | ||
? D extends Keys3<T, A, B, C> | ||
? E extends Keys4<T, A, B, C, D> | ||
? F extends Keys5<T, A, B, C, D, E> | ||
? G extends Keys6<T, A, B, C, D, E, F> | ||
? H extends Keys7<T, A, B, C, D, E, F, G> | ||
? readonly [A, B, C, D, E, F, G, H, ...NumOrString[]] | ||
: never | ||
: never | ||
: never | ||
: never | ||
: never | ||
: never | ||
: never | ||
: never; | ||
|
||
export type PathVal1<T, A> = A extends Keys<T> ? Val1<T, A> : never; | ||
|
||
export type PathVal2<T, A, B> = A extends Keys<T> | ||
? B extends Keys1<T, A> | ||
? Val2<T, A, B> | ||
: never | ||
: never; | ||
|
||
export type PathVal3<T, A, B, C> = A extends Keys<T> | ||
? B extends Keys1<T, A> | ||
? C extends Keys2<T, A, B> | ||
? Val3<T, A, B, C> | ||
: never | ||
: never | ||
: never; | ||
|
||
export type PathVal4<T, A, B, C, D> = A extends Keys<T> | ||
? B extends Keys1<T, A> | ||
? C extends Keys2<T, A, B> | ||
? D extends Keys3<T, A, B, C> | ||
? Val4<T, A, B, C, D> | ||
: never | ||
: never | ||
: never | ||
: never; | ||
|
||
export type PathVal5<T, A, B, C, D, E> = A extends Keys<T> | ||
? B extends Keys1<T, A> | ||
? C extends Keys2<T, A, B> | ||
? D extends Keys3<T, A, B, C> | ||
? E extends Keys4<T, A, B, C, D> | ||
? Val5<T, A, B, C, D, E> | ||
: never | ||
: never | ||
: never | ||
: never | ||
: never; | ||
|
||
export type PathVal6<T, A, B, C, D, E, F> = A extends Keys<T> | ||
? B extends Keys1<T, A> | ||
? C extends Keys2<T, A, B> | ||
? D extends Keys3<T, A, B, C> | ||
? E extends Keys4<T, A, B, C, D> | ||
? F extends Keys5<T, A, B, C, D, E> | ||
? Val6<T, A, B, C, D, E, F> | ||
: never | ||
: never | ||
: never | ||
: never | ||
: never | ||
: never; | ||
|
||
export type PathVal7<T, A, B, C, D, E, F, G> = A extends Keys<T> | ||
? B extends Keys1<T, A> | ||
? C extends Keys2<T, A, B> | ||
? D extends Keys3<T, A, B, C> | ||
? E extends Keys4<T, A, B, C, D> | ||
? F extends Keys5<T, A, B, C, D, E> | ||
? G extends Keys6<T, A, B, C, D, E, F> | ||
? Val7<T, A, B, C, D, E, F, G> | ||
: never | ||
: never | ||
: never | ||
: never | ||
: never | ||
: never | ||
: never; | ||
|
||
export type PathVal8<T, A, B, C, D, E, F, G, H> = A extends Keys<T> | ||
? B extends Keys1<T, A> | ||
? C extends Keys2<T, A, B> | ||
? D extends Keys3<T, A, B, C> | ||
? E extends Keys4<T, A, B, C, D> | ||
? F extends Keys5<T, A, B, C, D, E> | ||
? G extends Keys6<T, A, B, C, D, E, F> | ||
? H extends Keys7<T, A, B, C, D, E, F, G> | ||
? Val8<T, A, B, C, D, E, F, G, H> | ||
: never | ||
: never | ||
: never | ||
: never | ||
: never | ||
: never | ||
: never | ||
: never; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters