Skip to content

Instantly share code, notes, and snippets.

@gabemeola
Last active January 28, 2019 22:26
Show Gist options
  • Save gabemeola/1edec0acf753ec9dedd003630cc8f263 to your computer and use it in GitHub Desktop.
Save gabemeola/1edec0acf753ec9dedd003630cc8f263 to your computer and use it in GitHub Desktop.
Gets object type value if found. Otherwise uses default
type GetValue<Obj, Key extends keyof Obj | undefined, Default> = Key extends undefined
? Default
: Obj[Key];
/** Usage */
type BlueDefault = '#0078d7';
type BlueShades = {
50: '#e6f1fb',
100: '#b3d6f3',
400: '#0078d7',
500: '#0060ac',
600: '#004881',
}
declare const gray: <T extends keyof GrayShades = undefined>(shade?: T) => GetValue<GrayShades, T, GrayDefault>;
declare const color = gray()
declare const color50 = gray(50)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment