-
-
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
Spreading 2 sx props (one imported, one component prop) creates typescript errors #43991
Comments
The Alternatively you can restrict your app to only accept the object type if that is what you intend to use in these scenarios. Check the type for more details. You can e.g. use the |
What is weird to me is that if I put it in the same file: const sharedSx: SxProps<Theme> = {
bgcolor: 'primary.main',
};
const MyComponent: FC<{ sx: SxProps<Theme> }> = ({ sx }) => {
return <Box sx={{ ...sharedSx, ...sx }}>box content</Box>;
}; then it works. It also seems that import type { SystemStyleObject } from '@mui/material/styles'; Is not available, and I have to do import type { SystemStyleObject } from '@mui/system'; But okay, I think I'll do the latter. If there is nothing that looks wrong with that to you, the issue can be closed. |
@MonstraG Please follow this: https://mui.com/system/getting-started/the-sx-prop/#passing-the-sx-prop const MyComponent: FC<{ sx: SxProps<Theme> }> = ({ sx }) => {
return <Box sx={[sharedSx, …Array.isArray(sx) ? sx : [sx] ]}>box content</Box>;
}; I'm closing this issue. |
This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue. Note @MonstraG How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey. |
Steps to reproduce
Link to live example: https://stackblitz.com/edit/stackblitz-starters-d2gr1b?file=pages%2Findex.tsx
Steps:
Current behavior
Expected behavior
No crashy
Context
I believe it happens on 6.1.2 (latest v6) and 5.16.7 (latest v5).
Content is rendered correctly if typescript errors are ignored.
Your environment
Lastest versions of everything and tsconfig in repro, but duplicating here anyway:
npx @mui/envinfo
Search keywords: sx spread types typescript import
The text was updated successfully, but these errors were encountered: