Skip to content

Instantly share code, notes, and snippets.

@Sammons
Created November 6, 2018 04:11
Show Gist options
  • Save Sammons/3690be9651b0c33ad9c7bf7b74b5e360 to your computer and use it in GitHub Desktop.
Save Sammons/3690be9651b0c33ad9c7bf7b74b5e360 to your computer and use it in GitHub Desktop.
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