Skip to content

Instantly share code, notes, and snippets.

@arimariojesus
Last active October 9, 2022 23:17
Show Gist options
  • Save arimariojesus/4c4290a6d9168017109f105449069e3f to your computer and use it in GitHub Desktop.
Save arimariojesus/4c4290a6d9168017109f105449069e3f to your computer and use it in GitHub Desktop.
type ValidValues = string | number | Record<string, any> | Array<any> | undefined | null;
type DeepKey<T extends Record<string, any>, K extends string = string> = K extends keyof T
? T[K] extends ValidValues
? K
: never
: K extends `${infer TKey}.${infer Rest}`
? T[TKey] extends ValidValues
? DeepKey<Exclude<T[TKey], undefined>, Rest> extends never
? never
: K
: never
: never;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment