Interface OverridableComponent component prop should be optional
See original GitHub issueIn the OverridableComponent.d.ts the interface currently defines the component prop as required. This is incorrect because component is an optional property.
- This is not a v0.x issue.
- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior 🤔
A component that extends OverridableComponent should not be required to have a component property. I was able to fix this simply by adding a question mark to the interface definition
export interface OverridableComponent<M extends OverridableTypeMap> {
<C extends React.ElementType>(props: { component: C } & OverrideProps<M, C>): JSX.Element;
(props: DefaultComponentProps<M>): JSX.Element;
}
becomes
export interface OverridableComponent<M extends OverridableTypeMap> {
<C extends React.ElementType>(props: { component?: C } & OverrideProps<M, C>): JSX.Element;
(props: DefaultComponentProps<M>): JSX.Element;
}
…props: { component?: C }…
Current Behavior 😯
My IDE, IntelliJ Idea, gives a warning on any component that extends OverridableComponent “Element XXX doesn’t have the required attribute component” where XXX is MenuItem, Grid, etc.
Steps to Reproduce 🕹
Create a component that uses any component the extends OverridableComponent without supplying a component prop.
Context 🔦
This is just creating a lot of warnings and I don’t like to ignore warnings.
Your Environment 🌎
IDE IntelliJ Idea 2019.1.3 Ultimate Edition
Tech | Version |
---|---|
Material-UI | v4.2.1 |
React | v16.8.3 |
Browser | |
TypeScript | v3.4.5 |
etc. |
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8 (2 by maintainers)
Top GitHub Comments
I am using IntelliJ Idea Ultimate which includes all the features of PhpStorm and WebStorm. I “solved” the problem by telling the IDE that the
component
prop is not required. I believe that there are actually two problems, 1) as I stated when I opened the issue, component should be declared as optional, and 2) the JSX compiler is not properly checking thatcomponent
is required and that is why the builds are succeeding where the IDE gives warnings.@rpm911
This is a problem with the IDE. Issue ticket has been created here: WEB-40515.