I'm working on a TypeScript project where I have defined an interface called Theme which has a property called typography. The typography property is supposed to have a dynamic set of properties based on an enum called TypographyVariant. Here's my code:
export type TypographyVariant =
| 'label-large'
| 'label-medium'
| 'label-small';
export interface Theme {
typography: {
[key: TypographyVariant]: {
lineHeight: string;
fontSize: string;
letterSpacing?: string;
fontWeight?: number;
};
};
}
const theme: Theme {
typography: {
'label-large': {
lineHeight: '20px',
fontSize: '14px',
letterSpacing: '0.1px',
fontWeight: 500,
},
'label-medium': {
lineHeight: '16px',
fontSize: '12px',
letterSpacing: '0.5px',
fontWeight: 500,
},
'label-small': {
lineHeight: '16px',
fontSize: '11px',
letterSpacing: '0.5px',
fontWeight: 500,
},
}
};
My code editor is treating the typography object inside theme as {} type instead of what I have defined in Theme interface.
The problem is that when I try to define the theme object, my code editor is treating the typography property as an empty object instead of the dynamic set of properties defined in the Theme interface. I'm not sure why this is happening or how to fix it. Can anyone help me figure out what's going wrong here? Thanks!