-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Theme / TypeScript Module Augmentation broken when upgrading from 5.8.1 onwards #33440
Comments
Thanks for the report, #28244 (comment) should help, unless it is really related to specific version where this is broken. If that is the case, it could be related to: #33434 I would propose waiting for the today's release and trying to reproduce considering the comment shared above. If it still happens please create a repository with a reproduction. |
Since the issue is missing key information and has been inactive for 7 days, it has been automatically closed. If you wish to see the issue reopened, please provide the missing information. |
@mnajdova sorry for the delay, finally had some time to test latest (5.10.0 as of this comment) and was able to get it to work. Not right out of the box but for some reason I had to make some adjustments to the tsconfig files in the monorepo. Not really clear why it worked previously and broke after updating but all seems good now and my tsconfigs probably follow better practice 😄 If you would like more details about the previous setup to try and reproduce this probably somewhat obscure bug, I can put something together. Either way, thanks for the assistance! |
If the issue is resolved, I propose we close it. If someone hits something similar they can provide a reproduction and open a new issue. Thanks! |
@TurtIeSocks Can you share what you did in tsconfig? |
In my case I had misunderstood how to extend the interface, so, if it helps someone: declare module '@mui/material/Button' {
interface ButtonPropsColorOverrides {
neutral: true
}
} I was thinking it should have been of type string, as that's how you use it when you write |
Also make sure you actually import and export as modules, if you just use export * from 'x' without importing and exporting you will not export actual modules. This is in case of importing components and the overrides are recognised by your IDE, but not by tsc on build. |
@TurtIeSocks to echo @John-Dennehy, can you share what you did in tsconfig? Or any chance your project is open source? I haven't been able to find any good resources or any examples on sharing module augmentation across modules in a monorepo. |
@lnhrdt It works intermittently for me these days. Every so often it will break and sometime it will work fine. Unfortunately, I don't have a public repo to share but the behavior is inconsistent enough that maybe it's a problem with TS rather than the MUI lib 🤷 I don't have enough free time these days to really deep dive on this since I don't particularly understand the core issue. |
Came across this issue tonight and if anyone has any info regarding these things that would be amazing thanks
I gave this working for a typography augmentation, and tried the same thing for the palette (trying samples from MUI and also user feedback like this ticket, many different responses) where it works in the ide, but tsc borks. I tried the import module idea, but will give that another shot tomorrow because I might not have done it right. |
@McGern since I commented here a few months ago, I found a setup that's been working for our project. Our project is a monorepo managed with pnpm, using pnpm workspaces. We have a custom MUI theme defined in a module which is used as a dependency in other modules. I don't know how much of this is particular to our project but here are "tricks" that were necessary for us to get the types to work:
Good luck. If you learn anything helpful please share back! |
@lnhrdt, thanks for getting back so quickly really appreciate it. I don't know what the heck is going on. I was trying a whole bunch of stuff with rootDir and and tsconfig files (for a slightly different issue), and nothing was working (file location, declaration setup) with the augmentation, and even when I rolled back to what was working when I had less things - I had added a new typography type - it was no longer working. I rolled back everything including the rootDir changes which includes removing a generated tsconfig build file, and it seemed to work again, so probably something had gotten into the cache which didn't want to play ball. This is the code I was adding, and I was getting various errors in the terminal about "PaletteColor doesn't exist" and "PaletteColorOptions doesn't exist", if I imported the props directly I was then getting an error about unused props in the IDE. After my purge, it seemed to work again.
I put those declarations into an index.ts file that lower down (higher up?) than the theming and it seems to work (for now), but interestingly enough I didn't seem to need to explicitly import any of the augmentation files that I was using in the module declarations. My base theme has this in it (obvs to create the theme) Not entirely happy with the setup because I would rather have the declarations in a separate file, but I don't know the syntax/setup to get that working. Thanks again for your time. |
Duplicates
Latest version
Current behavior 😯
Firstly, thank you so much for the work put into this library. I use it with almost all of my React projects and love Mui <3
Onto the issue...
If I add the declaration into each file that makes use of the extended properties, the TS linter doesn't complain, but if I have the declarations in their own file (works fine with 5.8.1), then it no longer recognizes them as valid.
Small Example:
I can add the actual error in text if you want but it's mostly the usual TS jargon and it sums up with
No overload matches this call.
What I've tried:
import '@mui/material/Button
where the augmentation lives, per TS Module augmentation for adding variants to components not working #28244Expected behavior 🤔
Extending the theme via module augmentation in an external file is not an issue with 5.8.1 and the linter does not complain.
Steps to reproduce 🕹
Steps:
@mui/material
Context 🔦
Ideally I'd like to only be able to declare my module augmentations once and have it work throughout my project instead of having to do it in every file that makes use of the extended theme properties.
Thank you!
Your environment 🌎
npx @mui/envinfo
The text was updated successfully, but these errors were encountered: