Last active
October 9, 2022 23:17
-
-
Save arimariojesus/4c4290a6d9168017109f105449069e3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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