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.

`createMuiTheme` return type doesn't take into account merged objects

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

Thank you so much for this project – it is amazing!

Current Behavior 😯

I would like to add custom fields to the Theme object as described in the docs. However I struggle to get this to typecheck. The current Typescript definition for createMuiTheme is

export default function createMuiTheme(options?: ThemeOptions, ...args: object[]): Theme;

createMuiTheme returns a Theme object, rather than the type of deep merging options and args together.

Expected Behavior 🤔

The return type of createMuiTheme would reflect that args was merged in. For example the following wouldn’t fail (today it says Theme doesn’t have field foo).

createMuiTheme({}, {foo: "bar"}).foo

Proposed Solution

One possible solution would be to change the return type of createMuiTheme to

export default function createMuiTheme<T>(
  options?: ThemeOptions,
  ...args: Array<Partial<T>>
): Theme & T;

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
eps1loncommented, Mar 5, 2020

Customization is explained in our typescript guide. Does this work for you?

Changing the signature of createMuiTheme would be incomplete since it wouldn’t affect the type you read from context.

1reaction
blasterpistolcommented, Mar 6, 2020

@mcobzarenco it can works if you use this typed theme object directly, but not when it goes from the context

Read more comments on GitHub >

github_iconTop Results From Across the Web

createMuiTheme return type doesn't take into account merged ...
Current Behavior. I would like to add custom fields to the Theme object as described in the docs. However I struggle to get...
Read more >
Typescript and Material UI - pass object to createMuiTheme
If anyone's wondering, populating createMuiTheme({}) with an object works in JS, if not TS - I just tried it to find out. It...
Read more >
Create a Customized Color Theme in Material-UI - Medium
In the function, we will pass in an object as the argument and set the main value for the primary and secondary color...
Read more >
Merge Profiles - Oracle Help Center
Once the merge process is completed, the second profile — the profile you are merging into the original profile — will no longer...
Read more >
Building a React app with TypeScript and Material Design
Learn how to build a React application using TypeScript and Material Design.
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