Skip to content

[TypeScript] Fix theme options components types to use Theme#33434

Merged
siriwatknp merged 1 commit intomui:masterfrom
siriwatknp:typescript/theme
Jul 11, 2022
Merged

[TypeScript] Fix theme options components types to use Theme#33434
siriwatknp merged 1 commit intomui:masterfrom
siriwatknp:typescript/theme

Conversation

@siriwatknp
Copy link
Member

Issue

Currently, you can't use the custom node that augment from the theme in components style overrides:

import * as React from 'react';
import { createTheme, styled } from '@mui/material/styles';
import Box from '@mui/material/Box';

interface CustomNode {
  background: string;
  color: string;
}

declare module '@mui/material/styles' {
  interface ThemeOptions {
    customNode: CustomNode;
  }

  interface Theme {
    customNode: CustomNode;
  }
}

const customTheme = createTheme({
  customNode: {
    background: '#000',
    color: '#fff',
  },
  components: {
    MuiAppBar: {
      stylesOverrides: {
        root: ({ theme }) => ({
          // @ts-expect-error: this should work!
          backgroundColor: theme.customNode.background,
        })
      }
    }
  }
});

@siriwatknp siriwatknp added type: bug It doesn't behave as expected. typescript package: material labels Jul 8, 2022
@siriwatknp siriwatknp requested a review from mnajdova July 8, 2022 09:37
@mui-bot
Copy link

mui-bot commented Jul 8, 2022

No bundle size changes

Generated by 🚫 dangerJS against 9c5d69a

Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug It doesn't behave as expected. typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants