Last active
January 28, 2019 22:26
-
-
Save gabemeola/1edec0acf753ec9dedd003630cc8f263 to your computer and use it in GitHub Desktop.
Gets object type value if found. Otherwise uses default
This file contains hidden or 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 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