Skip to content

Instantly share code, notes, and snippets.

@ever-dev
Created May 14, 2022 02:39
Show Gist options
  • Save ever-dev/4a0bc7a3ff39f142391574c705089cdd to your computer and use it in GitHub Desktop.
Save ever-dev/4a0bc7a3ff39f142391574c705089cdd to your computer and use it in GitHub Desktop.
Type-safety for dictionaries
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