* Credit: https://stackoverflow.com/questions/77976781/typescript-type-for-getting-all-nested-key-paths-of-an-object-including-arrays
* A utility type that extracts all nested key paths from an object type as a union of string literals.
* Unlike TypeScript's built-in `keyof` which only provides top-level keys, `DeepKeyPaths<T>`
* recursively traverses the object structure to generate all possible key paths, including:
* - Nested object properties (e.g., `"address.street"`)
* - Array indices using both dot notation and bracket notation (e.g., `"hobbies.0"` and `"hobbies[0]"`)
* - Deeply nested paths (e.g., `"hobbies[0].name"`)
* The type intelligently handles arrays by excluding array methods (like `push`, `pop`, `map`, etc.)
* and only including numeric indices for array access.
* @template T - The object type to extract key paths from
* type PersonPaths = DeepKeyPaths<Person>;
* // | `hobbies.${number}`
* // | `hobbies[${number}]`
* // | `hobbies.${number}.name`
* // | `hobbies[${number}].name`
* type ConfigPaths = DeepKeyPaths<Config>;
* // | `features.${number}`
* // | `features[${number}]`
* This type uses several helper types:
* - `FixArr<T>`: Removes array methods from array types, keeping only numeric indices
* - `DeepKeys<T>`: Recursively generates key paths with dot prefixes
* - `DropInitDot<T>`: Removes the leading dot from generated paths
* - Objects: Recursively extracts all property paths
* - Arrays: Generates both dot notation (`array.0`) and bracket notation (`array[0]`) for indices
* - Nested structures: Traverses deeply nested objects and arrays
* - Primitives: Returns `never` for non-object types
type FixArr<T> = T extends readonly unknown[]
? Omit<T, Exclude<keyof unknown[], number>>
type DeepKeys<T> = T extends object
[K in (string | number) & keyof T]: `${
| (`${K}` extends `${number}`
: never)}${"" | DeepKeys<FixArr<T[K]>>}`;
}[(string | number) & keyof T]
type DropInitDot<T> = T extends `.${infer U}` ? U : T;
export type DeepKeyPaths<T> = DropInitDot<DeepKeys<FixArr<T>>>;