/** * Generates a union of all valid dot-notation key paths for an object type. * Useful for type-safe property access with nested objects. * * @template T - The object type to extract paths from. * @template D - Maximum depth to traverse (default 3 to avoid infinite recursion). * @example * ```typescript * type Person = { name: string; address: { city: string } } * type Paths = KeyPath // 'name' | 'address' | 'address.city' * ``` */ export type KeyPath = KeyPath_; /** * Internal recursive helper for KeyPath. * @internal */ type KeyPath_ = D extends S['length'] ? never : T extends object ? { [K in keyof T]-?: K extends string ? `${K}` | Join> : K extends number ? `[${K}]` | Join<`[${K}]`, KeyPath_> : never; }[keyof T] : ''; /** * Internal helper for joining path segments with dots. * @internal */ type Join = K extends string | number ? P extends string | number ? P extends `[${string}` ? `${K}${P}` : `${K}${'' extends P ? '' : '.'}${P}` : never : never; export {};