material-ui: [typescript] Typography in theme typed as `unknown`
Duplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Current behavior 😯
At the moment the typography key in the system’s theme is typed as unknown:
node_modules/@mui/system/createTheme/createTheme.d.ts
export interface ThemeOptions {
shape?: ShapeOptions;
breakpoints?: BreakpointsOptions;
direction?: Direction;
mixins?: unknown;
palette?: Record<string, any>;
shadows?: unknown;
spacing?: SpacingOptions;
transitions?: unknown;
components?: Record<string, any>;
typography?: unknown;
zIndex?: Record<string, number>;
}
Expected behavior 🤔
It should be typed to use TypographyVariants and TypographyVariantOptions or a @mui/system alternative so that we get type safety when using theme.typography like with @mui/material
Steps to reproduce 🕹
No response
Context 🔦
No response
Your environment 🌎
n/a
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 4
- Comments: 21 (11 by maintainers)
Please use
styledfrom@mui/material/styles;Hi @mgoetz-nerdery . I was experiencing the same issue but I could workaround by the code below. In my case
theme.transitionsdidn’t work because its type is ‘unknown’.We could work on this in v6 according to https://github.com/mui/material-ui/discussions/30988.
Hi, I am running into this issue now using MUI 5.8.6, even when I try to use module augmentation. I get this error when I try module augmentation:
Has anyone found a workaround for this issue?
We need to be clear on what package are we talking about but from the MUI system perspective, the
typographyshould be aRecord<TypographyScale, CSSObject>where the consumer can extends theTypographyScalevia module augmentation.I lean toward module augmentation because:
consistent experience with other MUI packages
It works with system
Boxwhereas generic don’t@Nicktho I agree we should improve the typings on these utils. Especially as we envision those would be used in different design systems. We could either, add typings that could be changed by module augmentation, or provide generics.