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.

ThemeOptions TS typings appear to be incomplete

See original GitHub issue

In the documentation for themes it is suggested that you can do the following:

const theme = createMuiTheme({
  palette: {
    contrastThreshold: 3,
    tonalOffset: 0.2,
  },
  status: {
    danger: 'orange',
  },
});

But it appears that the ThemeOptions interface accepted by createMuiTheme does not have the properties status, contrastThreshold or tonalOffset. Not sure if its the docs or the typings which are incorrect.

  • This is a v1.x issue (v0.x is no longer maintained).
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

Typings match what the documentation says you should be able to do

Current Behavior

Typings do not match what the documentation says you should be able to do

Your Environment

Tech Version
Material-UI v1.2.1
React v16.4.0
browser Chrome

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:20 (15 by maintainers)

github_iconTop GitHub Comments

15reactions
nagarajaycommented, Jun 29, 2018

@pelotom @Slessi - I am also stuck on this problem. I tried it as the docs say but could not get contrastThreshold and tonalOffset to work. Appreciate your help.

I think I got it to work as with the same logic, as given in docs, I changed the PaletteOptions in createPalette declaration.

import {
  Palette,
  PaletteOptions
} from "@material-ui/core/styles/createPalette";

declare module "@material-ui/core/styles/createPalette" {
  interface Palette {
    contrastThreshold: number;
    tonalOffset: number;
  }

  interface PaletteOptions {
    contrastThreshold?: number;
    tonalOffset?: number;
  }
}

If my approach is incorrect please let me know.

9reactions
Slessicommented, Jun 28, 2018

The docs are what brought me here: https://material-ui.com/customization/themes/#createmuitheme-options-theme

This was listed as an example:

import { createMuiTheme } from '@material-ui/core/styles';
import purple from '@material-ui/core/colors/purple';
import green from '@material-ui/core/colors/green';

const theme = createMuiTheme({
  palette: {
    primary: purple,
    secondary: green,
  },
  status: {
    danger: 'orange',
  },
});

And in TS this results in:

Argument of type ‘{ palette: { primary: Color; secondary: Color; }; status: { danger: string; }; }’ is not assignable to parameter of type ‘ThemeOptions | undefined’. Object literal may only specify known properties, and ‘status’ does not exist in type ‘ThemeOptions | undefined’.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ThemeOptions TS typings appear to be incomplete #11853
In the documentation for themes it is suggested that you can do the following: const theme = createMuiTheme({ palette: { contrastThreshold: ...
Read more >
MUI v5 - Extending Typography variant in TypeScript creates ...
My theme.ts config looks like that: import { createTheme, ThemeOptions } from "@mui/material/styles" ...
Read more >
@mui/types | Yarn - Package Manager
Important: This documentation covers modern versions of Yarn. For 1.x docs, see classic.yarnpkg.com. Yarn.
Read more >
material-ui/core/CHANGELOG.md - UNPKG
219, - Simplify the theme overrides with TypeScript for the components in the ... We will look for hiring a new full-time member...
Read more >
Extend Material-UI theme in TypeScript - In Plain English
So this article explains how you can extend Material-UI theme in TypeScript. Actually, if you master this article, you could extend other ...
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