From e2b35bc13cdf286d0e1cd60176eeb207525b064f Mon Sep 17 00:00:00 2001 From: Karsten Schmidt Date: Tue, 24 Mar 2020 20:13:38 +0000 Subject: [PATCH] feat(api): update Path alias, add doc strings --- packages/api/src/api/path.ts | 59 ++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/packages/api/src/api/path.ts b/packages/api/src/api/path.ts index 553b8085a2..6aca7731bd 100644 --- a/packages/api/src/api/path.ts +++ b/packages/api/src/api/path.ts @@ -19,20 +19,32 @@ import type { } from "./keyval"; /** - * Lookup path for nested data structures. + * Unchecked lookup path for nested data structures. */ -export type Path = PropertyKey | PropertyKey[]; +export type Path = readonly NumOrString[] | NumOrString; +/** + * Empty lookup path. + */ export type Path0 = readonly []; +/** + * Type checked lookup path (depth 1) + */ export type Path1 = A extends Keys ? readonly [A] : never; +/** + * Type checked lookup path (depth 2) + */ export type Path2 = A extends Keys ? B extends Keys1 ? readonly [A, B] : never : never; +/** + * Type checked lookup path (depth 3) + */ export type Path3 = A extends Keys ? B extends Keys1 ? C extends Keys2 @@ -41,6 +53,9 @@ export type Path3 = A extends Keys : never : never; +/** + * Type checked lookup path (depth 4) + */ export type Path4 = A extends Keys ? B extends Keys1 ? C extends Keys2 @@ -51,6 +66,9 @@ export type Path4 = A extends Keys : never : never; +/** + * Type checked lookup path (depth 5) + */ export type Path5 = A extends Keys ? B extends Keys1 ? C extends Keys2 @@ -63,6 +81,9 @@ export type Path5 = A extends Keys : never : never; +/** + * Type checked lookup path (depth 6) + */ export type Path6 = A extends Keys ? B extends Keys1 ? C extends Keys2 @@ -77,6 +98,9 @@ export type Path6 = A extends Keys : never : never; +/** + * Type checked lookup path (depth 7) + */ export type Path7 = A extends Keys ? B extends Keys1 ? C extends Keys2 @@ -93,6 +117,9 @@ export type Path7 = A extends Keys : never : never; +/** + * Type checked lookup path (depth 8) + */ export type Path8 = A extends Keys ? B extends Keys1 ? C extends Keys2 @@ -111,6 +138,10 @@ export type Path8 = A extends Keys : never : never; +/** + * Semi-typechecked lookup path (depth > 8). Only the first 8 levels are + * checked. + */ // prettier-ignore export type DeepPath = A extends Keys ? B extends Keys1 @@ -130,14 +161,23 @@ export type DeepPath = A extends Keys : never : never; +/** + * Value type for lookup path (depth 1) + */ export type PathVal1 = A extends Keys ? Val1 : never; +/** + * Value type for lookup path (depth 2) + */ export type PathVal2 = A extends Keys ? B extends Keys1 ? Val2 : never : never; +/** + * Value type for lookup path (depth 3) + */ export type PathVal3 = A extends Keys ? B extends Keys1 ? C extends Keys2 @@ -146,6 +186,9 @@ export type PathVal3 = A extends Keys : never : never; +/** + * Value type for lookup path (depth 4) + */ export type PathVal4 = A extends Keys ? B extends Keys1 ? C extends Keys2 @@ -156,6 +199,9 @@ export type PathVal4 = A extends Keys : never : never; +/** + * Value type for lookup path (depth 5) + */ export type PathVal5 = A extends Keys ? B extends Keys1 ? C extends Keys2 @@ -168,6 +214,9 @@ export type PathVal5 = A extends Keys : never : never; +/** + * Value type for lookup path (depth 6) + */ export type PathVal6 = A extends Keys ? B extends Keys1 ? C extends Keys2 @@ -182,6 +231,9 @@ export type PathVal6 = A extends Keys : never : never; +/** + * Value type for lookup path (depth 7) + */ export type PathVal7 = A extends Keys ? B extends Keys1 ? C extends Keys2 @@ -198,6 +250,9 @@ export type PathVal7 = A extends Keys : never : never; +/** + * Value type for lookup path (depth 8) + */ export type PathVal8 = A extends Keys ? B extends Keys1 ? C extends Keys2