-
-
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
[Typescript] PropTypes.Color does not allow new color variants #18966
Comments
This can be fixed with this diff: --- a/packages/material-ui/src/index.d.ts
+++ b/packages/material-ui/src/index.d.ts
@@ -46,7 +46,7 @@ export interface Color {
export namespace PropTypes {
type Alignment = 'inherit' | 'left' | 'center' | 'right' | 'justify';
- type Color = 'inherit' | 'primary' | 'secondary' | 'default';
+ type Color = 'inherit' | 'primary' | 'secondary' | 'warning' | 'info' | 'success' | 'default';
type Margin = 'none' | 'dense' | 'normal';
} Let me know if I should send a PR! |
The TypeScript definitions should match the implementation. I think that it would be better to duplicate the information until we unify it. |
We need to be careful with this on and check every usage if it matches the In the meantime you should be able to use module augmentation documented in our TypeScript guide. |
@eps1lon @oliviertassinari I do not think that users should be augmenting the internal built-in types to make them work with internal built-in colors. But that does make sense to have definitions matching the implementation. Perhaps we could rename the existing |
@r3dm1ke I'm sorry, I don't understand. What problem do you want to solve? |
@oliviertassinari I was looking into adding support for new colors to existing components and found out that the prop types for them do not allow the new colors. All the components reference the |
@r3dm1ke Thanks for the details. We also have this issue with the prop-types. If you add a new color, you will get a runtime warning. I was considering making the prop types a simple: 'string' in the past. Regarding |
@oliviertassinari I had followed your advice and focused on 70% of the rest. For instance, I had started with the |
Would the best solution be to remove the Color variable and to duplicate the enum every time? Then, as we move toward the support of any color from the palette, update the type according? |
@oliviertassinari @r3dm1ke Just an FYI, I have been searching all over the internet how to have a basic "success" button, and everything points to creating a styled component. This completely defeats the purpose of having a theme altogether. If all my forms have a success button, I would need to make a success button component and import it into my forms. We should be to be able to use IMO, users should either be able to define their own colors (success, warning, error, peaches, strawberries, etc), or be able to use material colors (red, green, blue, etc) and have the ability to override these shades to their hex values. I do understand the adherence to strict types and such, but not at the expense of basic features. Having a success and error button is a very very very basic thing in any UI library. |
@oliviertassinari Awesome! What's the timeline for this? |
Closing for the updated version of this issue #24778. |
Related to #13875
Current Behavior 😯
Types in
packages/material-ui/src/index.d.ts
, namelyPropTypes.Color
do not allow new color variants (success
,info
,warning
).Expected Behavior 🤔
PropTypes.Color
should allowsuccess
,info
andwarning
Steps to Reproduce 🕹
Try to pass
"info"
as a color to any component that supports it (none right now in master,Alert
in lab) and get a typescript warning.The text was updated successfully, but these errors were encountered: