`TypographyVariants` type augmentation not always working
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 99.1k
- Forks
- 32.5k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 106
Description
Duplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Steps to reproduce 🕹
No response
Current behavior 😯
Currently https://mui.com/material-ui/customization/typography/#adding-amp-disabling-variants instructs you to add the following type augmentations:
declare module '@mui/material/styles' {
interface TypographyVariants {
poster: React.CSSProperties;
}
// allow configuration using `createTheme`
interface TypographyVariantsOptions {
poster?: React.CSSProperties;
}
}
// Update the Typography's variant prop options
declare module '@mui/material/Typography' {
interface TypographyPropsVariantOverrides {
poster: true;
h3: false;
}
}
But in some cases accessing theme.typography.poster will still result in a type error:
packages/theme/src/componentsOverrides/MuiCssBaseline.ts:8:21 - error TS2339: Property 'poster' does not exist on type 'Typography'.
8 pre: typography.poster,
~~~~~~
Expected behavior 🤔
Accessing theme.typography.poster will never result in a type error.
In our project, I have only found one solution: augmenting Typography directly, instead of TypographyVariants (alias of Typography):
declare module "@mui/material/styles/createTypography" {
interface Typography {
poster: TypographyStyle;
}
}
Context 🔦
No response
Your environment 🌎
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the type augmentation example in the typography documentation and the failing access in packages/theme/src/componentsOverrides/MuiCssBaseline.ts. Compare TypographyVariants with the Typography declaration in @mui/material/styles/createTypography, then verify that theme.typography.poster is accepted without the direct augmentation workaround. Done means the documented augmentation works consistently and the reported TypeScript error no longer occurs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100