Skip to content

Instantly share code, notes, and snippets.

@scottshane
Forked from pffigueiredo/NestedKeyOf.ts
Created June 6, 2022 17:10
Show Gist options
  • Save scottshane/9f358fb8c989d52ca55ed34eaabc35c2 to your computer and use it in GitHub Desktop.
Save scottshane/9f358fb8c989d52ca55ed34eaabc35c2 to your computer and use it in GitHub Desktop.
NestedKeyOf
type NestedKeyOf<ObjectType extends object> =
{[Key in keyof ObjectType & (string | number)]: ObjectType[Key] extends object
? `${Key}` | `${Key}.${NestedKeyOf<ObjectType[Key]>}`
: `${Key}`
}[keyof ObjectType & (string | number)];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment