/** @module TypeScript: Nested Types */ /** * Prev is a long tuple that you can use to get the previous number (up to a max value). So Prev[3] is 2, and Prev[1] is 0. This limits the depth of recursion as we proceed deeper into the object tree. * Taken from https://newbedev.com/typescript-deep-keyof-of-a-nested-object */ export type Prev = [ never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...0[] ]; /** * Join concatenates two strings with a dot in the middle, unless the last string is empty. * So Join<"a","b.c"> is "a.b.c" while Join<"a",""> is "a". * Taken from https://newbedev.com/typescript-deep-keyof-of-a-nested-object * @typeParam L The left side of the string * @typeParam R The right side of the string */ export type Join = L extends string | number ? R extends string | number ? `${L}${"" extends R ? "" : "."}${R}` : never : never; /** * Leaves is a union of all nested elements of T which are not object types. * Taken from https://newbedev.com/typescript-deep-keyof-of-a-nested-object * @typeParam T The object from which leaves are derived. * @typeParam D The maximum allowed depth of recursion. */ export type Leaves = [D] extends [never] ? never : T extends object ? { [K in keyof T]-?: Join>; }[keyof T] : ""; /** * Paths is a union of all nested elements of T. * Taken from https://newbedev.com/typescript-deep-keyof-of-a-nested-object * @typeParam T The object from which leaves are derived. * @typeParam D The maximum allowed depth of recursion. */ export type Paths = [D] extends [never] ? never : T extends object ? { [K in keyof T]-?: K extends string | number ? `${K}` | Join> : never; }[keyof T] : ""; //# sourceMappingURL=nested-types.d.ts.map