-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
Can't augment common colors of theme palette anymore #20180
Comments
Note that |
@levrik From what I understand, we can close this issue, the augmentation should happen at the theme level, not the color one. |
@oliviertassinari For some reason I got a import { createPalette } from '@material-ui/core/styles'; |
@oliviertassinari No. Not really. As explained in my description the augmentation from the |
|
You can't augment Maybe you tried to augment colors the Theme? https://material-ui.com/guides/typescript/#customization-of-theme should help you achieve that. |
@oliviertassinari That's interesting. Because TypeScript didn't complain about the import of |
@eps1lon Yep. We've started on this guide but thought that a common Also want to note that we never patched |
You should only augment what you actually change. In your case you told typescript that you somehow changed Augmenting the theme is less harmful since we assume that you change the context value accordingly. |
@eps1lon Please take a look at the first Codesandbox I've posted. |
No, you changed
The guide I linked exactly described this. If you have further question then stackoverflow is the better place for these kind of issues. |
@eps1lon No. The guide doesn't answer the question about the |
@levrik While the generic approach is documented in https://material-ui.com/guides/typescript/#customization-of-theme, I have tried to update your codesandbox with no luck. I don't know how to process, but I believe it's possible. Maybe it would be great to have a demo for it?
Great catch, it sounds like we should keep the types in sync with the implementation. I believe this diff would do it :). diff --git a/packages/material-ui/src/styles/index.d.ts b/packages/material-ui/src/styles/index.d.ts
index febaa6212..7414c1adc 100644
--- a/packages/material-ui/src/styles/index.d.ts
+++ b/packages/material-ui/src/styles/index.d.ts
@@ -1,10 +1,6 @@
export * from './colorManipulator';
export { default as createMuiTheme, ThemeOptions, Theme, Direction } from './createMuiTheme';
-export {
- default as createPalette,
- PaletteColorOptions,
- SimplePaletteColorOptions,
-} from './createPalette';
+export { PaletteColorOptions, SimplePaletteColorOptions } from './createPalette';
export { default as createStyles } from './createStyles';
export { TypographyStyle, Variant as TypographyVariant } from './createTypography';
export { default as makeStyles } from './makeStyles'; Do you want to send a pull request? :) |
@eps1lon I'm a little confused by what you're proposing the solution to this problem is. Are you saying we should just add a new property to |
@hburrows This is important, the type should match reality |
@oliviertassinari That makes sense. Unless I'm missing something obvious that means there is no way to add additional colors to |
I was under the impression you could just add deep properties with module augmentation but seems like I misunderstood something. We'll add the ability to augment this. Quite unfortunate that this just happened to work by augmenting |
Current Behavior 😯
I couldn't find a way to augment the
common
key of aPalette
anymore.Expected Behavior 🤔
That it is possible like before.
Steps to Reproduce 🕹
Material-UI 4.9.5: https://codesandbox.io/s/peaceful-hodgkin-i05mi (working)
Material-UI 4.9.6: https://codesandbox.io/s/nameless-sun-r7nrv (not working)
Context 🔦
After upgrade to 4.9.6 of Material UI our builds started to break.
In version 4.9.6 the common colors are exported from
@material-ui/core/colors/common
asdefault
and with their nameCommonColors
as well. This made it possible to augment the types.Sadly TypeScript doesn't allow augmentation of
default
exports. That's why it isn't possible in 4.9.6 anymore sinceCommonColors
is gone and a const namedcommon
is just exported as default.Please see microsoft/TypeScript#14080 as reference for the mentioned TypeScript issue.
I also can't augment
Palette
directly since with augmentation we can't redefine an already defined key of thePalette
.I'm also wondering why the interface was removed. Before there was the interface, a type variable called
common
and the default export. By just getting the interface back and exported by its name like before this issue would be fixed.Your Environment 🌎
The text was updated successfully, but these errors were encountered: