From bca4565b43b4166f422aa4ba5d8399bb054bef66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dudak?= Date: Thu, 27 Jul 2023 11:52:37 +0200 Subject: [PATCH] [typescript] Add `component` field to `*Props` types (#38084) Co-authored-by: sai6855 <60743144+sai6855@users.noreply.github.com> --- .../mui-material/src/Accordion/Accordion.d.ts | 4 +- .../AccordionSummary/AccordionSummary.d.ts | 4 +- packages/mui-material/src/AppBar/AppBar.d.ts | 4 +- packages/mui-material/src/Avatar/Avatar.d.ts | 4 +- .../mui-material/src/Backdrop/Backdrop.d.ts | 4 +- packages/mui-material/src/Badge/Badge.d.ts | 4 +- .../BottomNavigation/BottomNavigation.d.ts | 4 +- .../BottomNavigationAction.d.ts | 4 +- .../src/Breadcrumbs/Breadcrumbs.d.ts | 4 +- packages/mui-material/src/Button/Button.d.ts | 4 +- .../mui-material/src/Button/Button.spec.tsx | 41 ++++++ .../src/ButtonBase/ButtonBase.d.ts | 4 +- .../src/ButtonGroup/ButtonGroup.d.ts | 4 +- packages/mui-material/src/Card/Card.d.ts | 8 +- packages/mui-material/src/Card/Card.spec.tsx | 34 +++++ .../src/CardActionArea/CardActionArea.d.ts | 4 +- .../src/CardContent/CardContent.d.ts | 4 +- .../src/CardHeader/CardHeader.spec.tsx | 18 +-- .../mui-material/src/CardMedia/CardMedia.d.ts | 4 +- packages/mui-material/src/Chip/Chip.d.ts | 4 +- .../mui-material/src/Container/Container.d.ts | 4 +- packages/mui-material/src/Dialog/Dialog.d.ts | 2 +- .../mui-material/src/Dialog/Dialog.spec.tsx | 19 ++- .../DialogContentText/DialogContentText.d.ts | 4 +- .../src/DialogTitle/DialogTitle.d.ts | 4 +- .../mui-material/src/Divider/Divider.d.ts | 4 +- packages/mui-material/src/Drawer/Drawer.d.ts | 2 +- .../mui-material/src/Drawer/Drawer.spec.tsx | 19 +++ packages/mui-material/src/Fab/Fab.d.ts | 4 +- .../src/FormControl/FormControl.d.ts | 4 +- .../src/FormHelperText/FormHelperText.d.ts | 4 +- .../FormHelperText/FormHelperText.spec.tsx | 61 ++++++++ .../mui-material/src/FormLabel/FormLabel.d.ts | 4 +- packages/mui-material/src/Grid/Grid.d.ts | 4 +- packages/mui-material/src/Grid/Grid.spec.tsx | 60 +++++++- packages/mui-material/src/Icon/Icon.d.ts | 4 +- .../src/IconButton/IconButton.d.ts | 4 +- .../mui-material/src/ImageList/ImageList.d.ts | 4 +- .../src/ImageListItem/ImageListItem.d.ts | 4 +- .../src/InputAdornment/InputAdornment.d.ts | 4 +- .../src/InputLabel/InputLabel.d.ts | 4 +- packages/mui-material/src/Link/Link.d.ts | 20 +-- packages/mui-material/src/Link/Link.spec.tsx | 39 ++++- packages/mui-material/src/List/List.d.ts | 4 +- .../mui-material/src/ListItem/ListItem.d.ts | 4 +- .../src/ListItemButton/ListItemButton.d.ts | 4 +- .../src/ListSubheader/ListSubheader.d.ts | 4 +- .../mui-material/src/MenuItem/MenuItem.d.ts | 4 +- .../src/MenuItem/MenuItem.spec.tsx | 68 +++++++++ .../mui-material/src/MenuList/MenuList.d.ts | 4 +- packages/mui-material/src/Modal/Modal.d.ts | 4 +- .../src/PaginationItem/PaginationItem.d.ts | 4 +- packages/mui-material/src/Paper/Paper.d.ts | 66 +++++---- .../mui-material/src/Paper/Paper.spec.tsx | 37 ++++- packages/mui-material/src/Paper/index.d.ts | 2 +- .../mui-material/src/Popover/Popover.d.ts | 2 +- .../mui-material/src/Popover/Popover.spec.tsx | 18 +++ .../ScopedCssBaseline/ScopedCssBaseline.d.ts | 4 +- .../mui-material/src/Skeleton/Skeleton.d.ts | 4 +- packages/mui-material/src/Slider/Slider.d.ts | 4 +- packages/mui-material/src/Stack/Stack.d.ts | 4 +- .../mui-material/src/Stack/Stack.spec.tsx | 15 ++ packages/mui-material/src/Step/Step.d.ts | 4 +- .../src/StepButton/StepButton.d.ts | 4 +- .../mui-material/src/Stepper/Stepper.d.ts | 4 +- .../mui-material/src/SvgIcon/SvgIcon.d.ts | 4 +- packages/mui-material/src/Tab/Tab.d.ts | 4 +- packages/mui-material/src/Table/Table.d.ts | 4 +- .../mui-material/src/TableBody/TableBody.d.ts | 4 +- .../src/TableContainer/TableContainer.d.ts | 4 +- .../src/TableFooter/TableFooter.d.ts | 4 +- .../mui-material/src/TableHead/TableHead.d.ts | 4 +- .../src/TablePagination/TablePagination.d.ts | 4 +- .../mui-material/src/TableRow/TableRow.d.ts | 4 +- .../src/TableSortLabel/TableSortLabel.d.ts | 4 +- packages/mui-material/src/Tabs/Tabs.d.ts | 4 +- .../src/TextField/TextField.spec.tsx | 16 +++ .../src/ToggleButton/ToggleButton.d.ts | 4 +- .../mui-material/src/Toolbar/Toolbar.d.ts | 4 +- .../src/Typography/Typography.d.ts | 135 +++++++++--------- .../src/Typography/typography.spec.tsx | 21 ++- packages/mui-system/src/Box/Box.d.ts | 2 +- 82 files changed, 751 insertions(+), 190 deletions(-) create mode 100644 packages/mui-material/src/Card/Card.spec.tsx create mode 100644 packages/mui-material/src/Drawer/Drawer.spec.tsx create mode 100644 packages/mui-material/src/FormHelperText/FormHelperText.spec.tsx create mode 100644 packages/mui-material/src/MenuItem/MenuItem.spec.tsx create mode 100644 packages/mui-material/src/Popover/Popover.spec.tsx create mode 100644 packages/mui-material/src/Stack/Stack.spec.tsx diff --git a/packages/mui-material/src/Accordion/Accordion.d.ts b/packages/mui-material/src/Accordion/Accordion.d.ts index d6790cb992caf0..7d443c40476f5b 100644 --- a/packages/mui-material/src/Accordion/Accordion.d.ts +++ b/packages/mui-material/src/Accordion/Accordion.d.ts @@ -86,6 +86,8 @@ declare const Accordion: OverridableComponent; export type AccordionProps< RootComponent extends React.ElementType = AccordionTypeMap['defaultComponent'], AdditionalProps = {}, -> = OverrideProps, RootComponent>; +> = OverrideProps, RootComponent> & { + component?: React.ElementType; +}; export default Accordion; diff --git a/packages/mui-material/src/AccordionSummary/AccordionSummary.d.ts b/packages/mui-material/src/AccordionSummary/AccordionSummary.d.ts index 35de2dfd7415ec..c015565cb62e84 100644 --- a/packages/mui-material/src/AccordionSummary/AccordionSummary.d.ts +++ b/packages/mui-material/src/AccordionSummary/AccordionSummary.d.ts @@ -46,6 +46,8 @@ declare const AccordionSummary: ExtendButtonBase; export type AccordionSummaryProps< RootComponent extends React.ElementType = AccordionSummaryTypeMap['defaultComponent'], AdditionalProps = {}, -> = OverrideProps, RootComponent>; +> = OverrideProps, RootComponent> & { + component?: React.ElementType; +}; export default AccordionSummary; diff --git a/packages/mui-material/src/AppBar/AppBar.d.ts b/packages/mui-material/src/AppBar/AppBar.d.ts index 6a3d52c76e285b..c6bc0104e0ced0 100644 --- a/packages/mui-material/src/AppBar/AppBar.d.ts +++ b/packages/mui-material/src/AppBar/AppBar.d.ts @@ -64,6 +64,8 @@ declare const AppBar: OverridableComponent; export type AppBarProps< RootComponent extends React.ElementType = AppBarTypeMap['defaultComponent'], AdditionalProps = {}, -> = OverrideProps, RootComponent>; +> = OverrideProps, RootComponent> & { + component?: React.ElementType; +}; export default AppBar; diff --git a/packages/mui-material/src/Avatar/Avatar.d.ts b/packages/mui-material/src/Avatar/Avatar.d.ts index 6b51d12a1ec5e1..2b19c9cb69c307 100644 --- a/packages/mui-material/src/Avatar/Avatar.d.ts +++ b/packages/mui-material/src/Avatar/Avatar.d.ts @@ -77,6 +77,8 @@ declare const Avatar: OverridableComponent; export type AvatarProps< RootComponent extends React.ElementType = AvatarTypeMap['defaultComponent'], AdditionalProps = {}, -> = OverrideProps, RootComponent>; +> = OverrideProps, RootComponent> & { + component?: React.ElementType; +}; export default Avatar; diff --git a/packages/mui-material/src/Backdrop/Backdrop.d.ts b/packages/mui-material/src/Backdrop/Backdrop.d.ts index f7e0a472fc42cb..2e0457336f11cb 100644 --- a/packages/mui-material/src/Backdrop/Backdrop.d.ts +++ b/packages/mui-material/src/Backdrop/Backdrop.d.ts @@ -118,6 +118,8 @@ declare const Backdrop: OverridableComponent; export type BackdropProps< RootComponent extends React.ElementType = BackdropTypeMap['defaultComponent'], AdditionalProps = {}, -> = OverrideProps, RootComponent>; +> = OverrideProps, RootComponent> & { + component?: React.ElementType; +}; export default Backdrop; diff --git a/packages/mui-material/src/Badge/Badge.d.ts b/packages/mui-material/src/Badge/Badge.d.ts index 8a94e795eec1eb..f107d7f3d33db4 100644 --- a/packages/mui-material/src/Badge/Badge.d.ts +++ b/packages/mui-material/src/Badge/Badge.d.ts @@ -108,6 +108,8 @@ declare const Badge: OverridableComponent; export type BadgeProps< RootComponent extends React.ElementType = BadgeTypeMap['defaultComponent'], AdditionalProps = {}, -> = OverrideProps, RootComponent>; +> = OverrideProps, RootComponent> & { + component?: React.ElementType; +}; export default Badge; diff --git a/packages/mui-material/src/BottomNavigation/BottomNavigation.d.ts b/packages/mui-material/src/BottomNavigation/BottomNavigation.d.ts index d354c52ed0aa21..3cbec3f280a31b 100644 --- a/packages/mui-material/src/BottomNavigation/BottomNavigation.d.ts +++ b/packages/mui-material/src/BottomNavigation/BottomNavigation.d.ts @@ -56,6 +56,8 @@ declare const BottomNavigation: OverridableComponent; export type BottomNavigationProps< RootComponent extends React.ElementType = BottomNavigationTypeMap['defaultComponent'], AdditionalProps = {}, -> = OverrideProps, RootComponent>; +> = OverrideProps, RootComponent> & { + component?: React.ElementType; +}; export default BottomNavigation; diff --git a/packages/mui-material/src/BottomNavigationAction/BottomNavigationAction.d.ts b/packages/mui-material/src/BottomNavigationAction/BottomNavigationAction.d.ts index 79a939d1c86d17..08d850dddbece3 100644 --- a/packages/mui-material/src/BottomNavigationAction/BottomNavigationAction.d.ts +++ b/packages/mui-material/src/BottomNavigationAction/BottomNavigationAction.d.ts @@ -65,6 +65,8 @@ declare const BottomNavigationAction: ExtendButtonBase< export type BottomNavigationActionProps< RootComponent extends React.ElementType = ButtonBaseTypeMap['defaultComponent'], AdditionalProps = {}, -> = OverrideProps, RootComponent>; +> = OverrideProps, RootComponent> & { + component?: React.ElementType; +}; export default BottomNavigationAction; diff --git a/packages/mui-material/src/Breadcrumbs/Breadcrumbs.d.ts b/packages/mui-material/src/Breadcrumbs/Breadcrumbs.d.ts index 636d304db8643f..9ce23f7a8c06a2 100644 --- a/packages/mui-material/src/Breadcrumbs/Breadcrumbs.d.ts +++ b/packages/mui-material/src/Breadcrumbs/Breadcrumbs.d.ts @@ -100,6 +100,8 @@ declare const Breadcrumbs: OverridableComponent; export type BreadcrumbsProps< RootComponent extends React.ElementType = BreadcrumbsTypeMap['defaultComponent'], AdditionalProps = {}, -> = OverrideProps, RootComponent>; +> = OverrideProps, RootComponent> & { + component?: React.ElementType; +}; export default Breadcrumbs; diff --git a/packages/mui-material/src/Button/Button.d.ts b/packages/mui-material/src/Button/Button.d.ts index df3a0cfc591514..1bd7dd18ece3d6 100644 --- a/packages/mui-material/src/Button/Button.d.ts +++ b/packages/mui-material/src/Button/Button.d.ts @@ -125,6 +125,8 @@ declare const Button: ExtendButtonBase; export type ButtonProps< RootComponent extends React.ElementType = ButtonTypeMap['defaultComponent'], AdditionalProps = {}, -> = OverrideProps, RootComponent>; +> = OverrideProps, RootComponent> & { + component?: React.ElementType; +}; export default Button; diff --git a/packages/mui-material/src/Button/Button.spec.tsx b/packages/mui-material/src/Button/Button.spec.tsx index 1250869cfb83d9..57c051d5e2a13f 100644 --- a/packages/mui-material/src/Button/Button.spec.tsx +++ b/packages/mui-material/src/Button/Button.spec.tsx @@ -1,5 +1,6 @@ import * as React from 'react'; import Button, { ButtonProps } from '@mui/material/Button'; +import MaterialUiLink, { LinkProps as MaterialUiLinkProps } from '@mui/material/Link'; import { Link as ReactRouterLink, LinkProps } from 'react-router-dom'; import { expectType } from '@mui/types'; @@ -9,10 +10,47 @@ const TestOverride = React.forwardRef((props, re
)); +type CustomLinkProps = MaterialUiLinkProps; +const CustomLink: React.FC> = ({ children, ...props }) => { + return ( + + {children} + + ); +}; + function FakeIcon() { return
Icon
; } +const props1: ButtonProps<'div'> = { + component: 'div', + onChange: (event) => { + expectType, typeof event>(event); + }, +}; + +const props2: ButtonProps = { + onChange: (event) => { + expectType, typeof event>(event); + }, +}; + +const props3: ButtonProps = { + component: TestOverride, + x: 2, +}; + +const props4: ButtonProps = { + component: TestOverride, + // @ts-expect-error TestOverride does not accept incorrectProp + incorrectProp: 3, +}; + +const props5: ButtonProps = { + component: TestOverride, +}; + const buttonTest = () => (
@@ -36,6 +74,9 @@ const buttonTest = () => ( + {/* By default the underlying component is a button element */}