Created
May 14, 2022 02:39
-
-
Save ever-dev/4a0bc7a3ff39f142391574c705089cdd to your computer and use it in GitHub Desktop.
Type-safety for dictionaries
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 GetDictValue<T extends string, O> = T extends `${infer A}.${infer B}` | |
? A extends keyof O | |
? GetDictValue<B, O[A]> | |
: never | |
: T extends keyof O | |
? O[T] | |
: never; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment