-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
Closed
Closed
Copy link
Labels
component: PopoverThe React component.The React component.customization: cssDesign CSS customizability.Design CSS customizability.typescript
Description
Steps to reproduce
Link to live example: https://stackblitz.com/edit/react-1rixxg?file=Demo.tsx
Steps:
- Create a component with slots (I use
Popover) - override the
sxproperty of a slot (I usepaper) - try using a function as the value, to leverage a theme-based value for example
- The code runs correctly
- But TypeScript will complain that parameter t is of type any (assuming you use
tas the theme prop)
Current behavior
Here is the Popover example from the docs.
<Popover
id={id}
open={open}
anchorEl={anchorEl}
onClose={handleClose}
anchorOrigin={{
vertical: 'bottom',
horizontal: 'left',
}}
slotProps={{
paper: {
sx: {
color: (t) => t.palete.primary.dark,
},
},
}}
>
<Typography sx={{ p: 2 }}>The content of the Popover.</Typography>
</Popover>TypeScript will complain about the type of t in the sx prop for the paper slot:

But the code runs just fine, as expected.
Expected behavior
TypeScript should recognize a theme-based override and not complain.
Context
Trying to override properties of a slot with theme-based values.
Your environment
npx @mui/envinfo
System:
OS: macOS 14.6.1
Binaries:
Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm
pnpm: Not Found
Browsers:
Chrome: 128.0.6613.114
Edge: 128.0.2739.42
Safari: 17.6
npmPackages:
@emotion/react: ^11.13.3 => 11.13.3
@emotion/styled: ^11.13.0 => 11.13.0
@mui/base: 5.0.0-beta.58
@mui/core-downloads-tracker: 6.0.1
@mui/icons-material: ^6.0.1 => 6.0.1
@mui/lab: ^6.0.0-beta.8 => 6.0.0-beta.8
@mui/material: ^6.0.1 => 6.0.1
@mui/private-theming: 6.0.1
@mui/styled-engine: 6.0.1
@mui/system: 6.0.1
@mui/types: 7.2.16
@mui/utils: 5.16.6
@mui/x-data-grid: 7.15.0
@mui/x-data-grid-pro: ^7.15.0 => 7.15.0
@mui/x-date-pickers: 7.15.0
@mui/x-date-pickers-pro: ^7.15.0 => 7.15.0
@mui/x-internals: 7.15.0
@mui/x-license: 7.15.0
@types/react: ^18.3.4 => 18.3.4
react: ^18.3.1 => 18.3.1
react-dom: ^18.3.1 => 18.3.1
typescript: ^5.5.4 => 5.5.4
Search keywords: slotprops sx
Metadata
Metadata
Assignees
Labels
component: PopoverThe React component.The React component.customization: cssDesign CSS customizability.Design CSS customizability.typescript
Projects
Status
Done