As someone who has been using React for quite some time, I am now looking to integrate Typescript into my projects. In the past, I would create large "container" objects like this:
const theme = {
colors: {
primary: '#00f',
accent: '#f70',
},
sizes: {
base: '16px',
},
};
I am wondering if there is a more efficient way to define a type for such an object. It feels cumbersome to have to define interfaces for each member and then repeat them all over again when assigning values:
interface ThemeType { colors: ThemeColors, sizes: ThemeSizes }
interface ThemeColors { primary: string, accent: string }
interface ThemeSizes { base: string }
const theme : ThemeType = {
// ...
};
Is there a more concise or streamlined approach to achieve this? Any suggestions would be greatly appreciated.