-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[Box] Type error when too many properties exist in JSX.IntrinsicElements #34068
Comments
Box
prdouces type error when too many properties exist in JSX.IntrinsicElementsBox
produces type error when too many properties exist in JSX.IntrinsicElements
For those facing this issue, I was able to workaround it by patching Box.d.ts like so: *
* - [Box API](https://mui.com/material-ui/api/box/)
*/
-declare const Box: OverridableComponent<BoxTypeMap>;
+declare const Box: <D extends React.ElementType = 'div'>(props: BoxProps<D> & { component?: D }) => JSX.Element;
export type BoxProps<
D extends React.ElementType = BoxTypeMap['defaultComponent'], I'm not sure if this is a good long-term fix, but it seems to work from what I can tell. I suppose the way |
The above solution does seem to lose automatic typing for event handlers (i.e., the type of the |
I have the same problem with the latest version (npm). I created a component for a workaround if anyone wants to use it: // ** MUI Imports
import MuiBox from '@mui/material/Box'
import {BoxProps} from '@mui/material/Box'
const Box = (props: BoxProps) => {
return (
<MuiBox
{...props}
component="div"
/>
)
}
export type {BoxProps}
export default Box |
Does it happen with only |
Yes. |
Any news on this? I haven't found any solution to this, only workarounds. |
I'm working on a large code base and changing the imports or updating the component type everywhere is not deemed acceptable, so I am also still looking for a real solution. |
I have a workaround by patching the
|
Worked fine for me and I think it's the cleaner workaround for now |
This update was involved on |
With the mui 5.14.1 update this error occurs on even more components, e.g. ToggleButton, Typography, Card, Divider, etc. |
Yeah, while with |
It looks like this was caused by these added lines in #35924. The patch to fix it would be to remove the added lines in |
Box
produces type error when too many properties exist in JSX.IntrinsicElements
@michaldudak Can you reopen this issue, since the fix was reverted in #38356? |
Yes, of course. |
@michalmuchakr What version are you on? This error is known to occur for other components in |
I'm using |
@michalmuchakr, could you create a codesandbox showing the issue? I'm surprised the problem exists in TextField. |
We experienced this issue in joy-ui but somehow it just happened yesterday and we've been updating the betas on each new release 🤷 . Now when I roll back I can still see the issue. After a lot of refactoring we had to remove ALL usages of const Box = styled("div")({}) // Some style So generally This cost us a lot of nerv and unplanned refactoring. Please prioritize this issue as it can/will break a lot of big projects. I'm a bit scared to check which new bugs were introduced by the refactoring but hopefully our tests will catch them. ❤️ EDIT: this is probably helpful ;)
|
@pixelass Does the issue exist when you explicitly provide a |
It seems to have happened after the project reached a certain size. Not sure if that makes sense. Unrelated to whether props were added or not. Suddenly ALL instances were affected. |
To be clear - the instances of the Box where you have both the |
@michaldudak all instances of <Box>Foo</Box>
<Box sx={{m: 2}}>Foo</Box>
<Box component="footer">Foo</Box>
<Box data-testid="foo">Foo</Box> I would have to checkout an older version of a closed source project to be sure though. I would love to create a repro, but I will have to see when I find time, since this is a rather strange and somewhat hard to reproduce. |
@michaldudak Out of nothing this just happened: Even a simple self closing Box causes the same issue. No props on the box. I just edited a totally unrelated file (which is not even imported in any way) |
I haven't noticed it on my own. A repro would help us investigate this issue a lot. |
After checking the OP of this thread I added fiber and drei from react-three Check the pages/index.tsx of this repo: |
This does make sense since it is highly likely that I added react-three/fiber in the affected repositories |
Please see this discussion covering the issue: pmndrs/react-three-fiber#1752 |
Well ran into this issue again. Patching three fiber to make it's added IntrinsicElements elements optional fixed it for now, but I feel like fixing other packages for a bug in MUI isn't the best approach. |
@Hanro50 It is actually a problem in react-three/fiber, as they are polluting the JSX namespace instead of creating their own scoped types. It offers a neat developer experience but comes with drawbacks. Also typescript is not as developed as other type systems, so we can hope that in future releases of typescript this will improve this behavior. |
Thank you @pixelass @Hanro50 removing react-three/fiber from my project (wasn't using it anymore anyways) fixed my intellisense issue, now it suggests the right props for all my material components including all of the style and sx props which where starting to get bothersome |
@michaldudak Any chance we could fix this in MUI 6.0 by merging #38168 as a breaking change? It seems like it would be better to avoid the inconsistent behavior that currently exists as you described here. For example, while some cases work like this one: const StyledBox = styled(Box)(() => ({
fontSize: "100px",
color: "white"
}));
<StyledBox component="span" sx={{ width: 300 }} /> once you start adding props for the component in question, it stops working, like this, where the <StyledBox component="img" src="https://mui.com/" alt="Material UI" /> It seems like this could be a good time to rip off the band-aid and tell people to cast the result of |
@aarongarciah, @DiegoAndai, what do you think? |
Duplicates
Latest version
Current behavior 😯
The
Box
component produces type errors when too many properties are added to JSX.IntrinsicElements.Expected behavior 🤔
The
Box
component should not produce type error when properties are added to JSX.IntrinsicElements.Steps to reproduce 🕹
When using
@mui/material
in the same project with@react-three/fiber
and@react-three/drei
using theBox
component produces a type error:Output
Compiler Options
Playground Link: Provided
This behavior can also be replicated without any dependence on
@react-three/fiber
or@react-three/drei
by adding properties toJSX.IntrinsicElements
:Output
Compiler Options
Playground Link: Provided
Context 🔦
This is primarily in the context of trying to use
@react-three/fiber
and@react-three/drei
in the same project as@mui/material
. Related issues include #29176 and https://stackoverflow.com/questions/68692230/ts-expression-produces-a-union-type-that-is-too-complex-to-represent-with-materi. The latter issue seems to suggest this has been resolved, but I do not believe it has been.Your environment 🌎
tsconfig.json
included above.The text was updated successfully, but these errors were encountered: