question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[typescript] Typography in theme typed as `unknown`

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
johnta0commented, Aug 21, 2022

Hi @mgoetz-nerdery . I was experiencing the same issue but I could workaround by the code below. In my case theme.transitions didn’t work because its type is ‘unknown’.

...
      transition: (theme.transitions as any).create('width'),
...
2reactions
mgoetz-nerderycommented, Jul 11, 2022

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:

Subsequent property declarations must have the same type.  Property 'typography' must be of type 'unknown', but here has type 'Typography | undefined'.

Has anyone found a workaround for this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

[typescript] Typography in theme typed as unknown #30678
So, looks like we need to update the types for the typography inside the system's ThemeOptions and that should solve the issue, as...
Read more >
MUI v5 - Extending Typography variant in TypeScript creates ...
const theme: Theme = createTheme({ typography: { h1Bold: ... To update Typography variant in Typescript, use the following code:
Read more >
TypeScript - Theme UI
The Theme type represents all possible themes. It might be what you need when you're writing a library of reusable components or an...
Read more >
TypeScript - Emotion
You can define a theme type by extending our type declarations via your own declarations file. emotion.d.ts. import '@emotion/react' declare module '@emotion ...
Read more >
TypeScript - Material-UI
However type widening rears its ugly head once more if you try to make the styles depend on the theme: withStyles(({ palette, spacing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found