Created
November 6, 2018 04:11
-
-
Save Sammons/3690be9651b0c33ad9c7bf7b74b5e360 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
function Strictly<T extends { [key: string]: Values }, Values extends string | number, O extends {}>(target: T, augmentations?: O) { | |
return Object.assign(target, augmentations) | |
} | |
// for example when building a prototype object | |
const defaultConfig = Strictly( | |
{ | |
state: 'MO', // "MO", not string | |
settingType: 'state-settings' | |
}, { | |
branding: Strictly({ | |
type: 'header', | |
color: colors.green, | |
width: 500 | |
}) | |
}); | |
defaultConfig.branding.type; // "header", not string | |
defaultConfig.branding.width; // 500, not number |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment