Skip to content

Instantly share code, notes, and snippets.

@webstrand
Created April 20, 2023 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webstrand/2e1b18479c39761227087a79e36444da to your computer and use it in GitHub Desktop.
Save webstrand/2e1b18479c39761227087a79e36444da to your computer and use it in GitHub Desktop.
Recursively generate a list of all paths into some object
type StringSerialized<T extends object, Prefix extends string = ""> = T extends Array<any> ? {
[P in keyof T & `${bigint}`]: `-${P}` extends `${bigint}`
? | `${Prefix}${P}`
| StringSerialized<T[P] & object, `${Prefix}${P}.`>
: never
}[keyof T & `${bigint}`] : {
[P in keyof T & string]:
| `${Prefix}${P}`
| StringSerialized<T[P] & object, `${Prefix}${P}.`>
}[keyof T & string];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment