Closed
Description
- 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 🤔
MenuItemProps should be typed with correct 'button' override by default the when imported
Current Behavior 😯
from core/MenuItem/MenuItem.d.ts
:
declare const MenuItem: OverridableComponent<ListItemTypeMap<{ button: false }, 'li'>> &
ExtendButtonBase<ListItemTypeMap<{ button?: true }, 'li'>>;
export type MenuItemProps<D extends React.ElementType = 'li', P = {}> = OverrideProps<
ListItemTypeMap<P, D>,
D
>;
P
parameter of menu Item props default to {}
instead of { button?: true }
resulting in an error when you want to use it directly:
var a: MenuItemProps = {};
<MenuItem {...a}/>
// error:
// Types of property 'button' are incompatible.
// Type 'boolean | undefined' is not assignable to type 'true | undefined'.
// Type 'false' is not assignable to type 'true | undefined'
To dismiss the error, type MenuItemProps
needs to be declared like this:
MenuItemProps<'li', { button?: true }>
Steps to Reproduce 🕹
import MenuItem, { MenuItemProps } from "@material-ui/core/MenuItem";
/* ... */
var a: MenuItemProps = {};
<MenuItem {...a}/>
Link:
Context 🔦
I am migrating to MUIv4 from v3. I had a component taking MenuItemProps
in its own props to be passed to its children MenuItem
s. I am now forced to type this as MenuItemProps<'li', { button?: true }>
.
Your Environment 🌎
Tech | Version |
---|---|
Material-UI | v4.1.1 |
React | v16.8 |
Browser | Chrome 74 |
TypeScript | 3.4.1 |