/** * Generates all possible dot-separated paths for a given object type, including paths through arrays. * Turns `{ a: { b: string }, arr: { c: number }[] }` into `"a" | "a.b" | "arr" | "arr.0" | "arr.0.c"` * @template T The object type to generate paths for. * @template Prev A helper type to accumulate the current path prefix. */ export type DotPath = { [K in keyof T & string]: T[K] extends (infer U)[] ? `${Prev}${K}.${number}` | `${Prev}${K}` | DotPath : T[K] extends Record ? `${Prev}${K}` | DotPath : `${Prev}${K}`; }[keyof T & string]; /** * Retrieves the type of the value located at a specified dot-separated path within an object type. * Supports paths through nested objects and arrays. * @template T The object type to retrieve the value from. * @template P The dot-separated path to the value. */ export type PathValue = P extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? T[Key] extends (infer U)[] ? Rest extends `${number}.${infer SubRest}` ? PathValue : Rest extends `${number}` ? U : never : PathValue : never : P extends keyof T ? T[P] : T extends (infer U)[] ? P extends `${number}` ? U : never : never; /** * Utility function that returns the value at a given path in an object. * @param obj The object to retrieve the value from. * @param path The path to the value in the object. * @returns The value at the given path or undefined if the path is invalid. */ export declare function getValueAtPath>(obj: T, path: P): PathValue; export declare function setValueAtPath>(obj: T, path: P, value: PathValue): T;