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.

createTheme throwing type errors with typescript

See original GitHub issue

createTheme is throwing compile time error

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

node_modules/@material-ui/core/styles/createTheme.d.ts:10:18 - error TS2430: Interface 'import("/Users/vrajole/sg-core/frontend-monorepo/packages/lib/auth/node_modules/@material-ui/core/styles/createTheme").ThemeOptions' incorrectly extends interface 'import("/Users/vrajole/sg-core/frontend-monorepo/packages/lib/auth/node_modules/@material-ui/system/createTheme/createTheme").ThemeOptions'.
  Types of property 'zIndex' are incompatible.
    Type 'Partial<ZIndex> | undefined' is not assignable to type 'Record<string, number> | undefined'.
      Type 'Partial<ZIndex>' is not assignable to type 'Record<string, number>'.
        Property 'mobileStepper' is incompatible with index signature.
          Type 'number | undefined' is not assignable to type 'number'.
            Type 'undefined' is not assignable to type 'number'.

10 export interface ThemeOptions extends SystemThemeOptions {
                    ~~~~~~~~~~~~


Found 1 error.

error Command failed with exit code 1.

Expected Behavior 🤔

Steps to Reproduce 🕹

Steps:

  1. Use material ui mentioned version with typescript (No need to create new theme)

Context 🔦

Your Environment 🌎

@material-ui/core: 5.0.0-alpha.37,
@material-ui/icons: 5.0.0-alpha.37,
Node: 15.8.0 
Yarn: 1.22.4
npm: 7.17.0 
`npx @material-ui/envinfo`
  Don't forget to mention which browser you used.
  Output from `npx @material-ui/envinfo` goes here.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:9
  • Comments:21 (13 by maintainers)

github_iconTop GitHub Comments

12reactions
oliviertassinaricommented, Oct 30, 2021

@vishalrajole Interesting, @mnajdova I see 3 solutions:

  1. We allow undefined in the system createTheme()
diff --git a/packages/material-ui-system/src/createTheme/createTheme.d.ts b/packages/material-ui-system/src/createTheme/createTheme.d.ts
index 9b9d1c2e8b..c6f1f72054 100644
--- a/packages/material-ui-system/src/createTheme/createTheme.d.ts
+++ b/packages/material-ui-system/src/createTheme/createTheme.d.ts
@@ -17,7 +17,7 @@ export interface ThemeOptions {
   transitions?: unknown;
   components?: Record<string, any>;
   typography?: unknown;
-  zIndex?: Record<string, number>;
+  zIndex?: Record<string, number | undefined>;
 }

 export interface Theme {
  1. We don’t allow undefined in the core createTheme(): https://github.com/mui-org/material-ui/blob/2d530cde534deda0651ed32d56fa0f40c4afc38b/packages/material-ui/src/styles/zIndex.d.ts#L11

https://stackoverflow.com/questions/54489817/typescript-partialt-type-without-undefined.

  1. When we merge the two, we omit zIndex.
diff --git a/packages/material-ui/src/styles/createTheme.d.ts b/packages/material-ui/src/styles/createTheme.d.ts
index 26280d93c0..080a4db73c 100644
--- a/packages/material-ui/src/styles/createTheme.d.ts
+++ b/packages/material-ui/src/styles/createTheme.d.ts
@@ -7,7 +7,7 @@ import { Transitions, TransitionsOptions } from './createTransitions';
 import { ZIndex, ZIndexOptions } from './zIndex';
 import { Components } from './components';

-export interface ThemeOptions extends SystemThemeOptions {
+export interface ThemeOptions extends Omit<SystemThemeOptions, 'zIndex'> {
   mixins?: MixinsOptions;
   components?: Components;
   palette?: PaletteOptions;

PR welcome.

2reactions
mnajdovacommented, Oct 20, 2021

Hi, I’d like to take this issue. Is there a preference for any of these 3 solutions, @oliviertassinari?

@oliveirag thanks for the interest and sorry for the late response. I would go with Option 3 😃 Feel free to grab it if you are still interested.

Read more comments on GitHub >

github_iconTop Results From Across the Web

createTheme throwing type errors with typescript · Issue #27139
createTheme is throwing compile time error The issue is present in the latest release. I have searched the issues of this repository and...
Read more >
Typescript Type error when Adding custom new property 'tab ...
Correct theme setting. import { createTheme } from "@material-ui/core"; const arcBlue = "#0B72B9"; const arcOrange = "#FF8C00"; ...
Read more >
Get a catch block error message with TypeScript - Kent C. Dodds
TypeScript forces you to acknowledge you can't know what was thrown making getting the error message a pain. Here's how you can manage...
Read more >
Theming - Material UI - MUI
To promote greater consistency between apps, light and dark theme types are available to choose from. ... It will throw an error if...
Read more >
Extend Material-UI theme in TypeScript - In Plain English
Combination of React and TypeScript is super powerful and beautiful. ... The answer is extending Material UI theme type by yourself.
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