`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:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
@mcobzarenco it can works if you use this typed theme object directly, but not when it goes from the context