material-ui: [Popper] Incompatible props: `onResize` and `onResizeCapture`
Duplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Steps to reproduce 🕹
Link to live example:
Steps:
- Use dependencies @mui/lab:.0.0-alpha.110 and @mui/material:5.10.16
- Render a Autocomplete Component with property
PopperComponent={popperProps => <Popper {...popperProps} />
Current behavior 😯
Typescript error:
Type '{ anchorEl: HTMLDivElement | undefined; style: { width: number | undefined; }; key?: Key | null | undefined; className?: string | undefined; component?: "div" | undefined; ... 268 more ...; sx?: SxProps<...> | undefined; }' is missing the following properties from type 'Pick<PopperProps, "key" | "className" | "style" | "component" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | ... 265 more ... | "onResizeCapture">': onResize, onResizeCapture
PopperUnstyledOwnProps in mui/base does not provide the onResize and onResizeCapture props picked by the mui/material
Popper components props
Expected behavior 🤔
No Typescript error
Context 🔦
We have to pin @mui/material to version 5.10.15 in order to build our project even though we would prefer to do minor upgrades automatically.
Workaround
See https://github.com/mui/material-ui/issues/35287#issuecomment-1337250566.
Your environment 🌎
System: OS: Linux 5.10 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish) Binaries: Node: 16.18.1 - ~/.nvm/versions/node/v16.18.1/bin/node Yarn: 3.2.0 - ~/.nvm/versions/node/v16.18.1/bin/yarn npm: 8.19.2 - ~/.nvm/versions/node/v16.18.1/bin/npm Browsers: Chrome: Not Found Firefox: 106.0.2 npmPackages: @emotion/react: 11.10.5 @emotion/styled: 11.10.5 @mui/base: 5.0.0-alpha.108 @mui/core-downloads-tracker: 5.10.16 @mui/icons-material: 5.10.16 @mui/lab: 5.0.0-alpha.110 @mui/material: 5.10.16 @mui/private-theming: 5.10.16 @mui/styled-engine: 5.10.16 @mui/styles: 5.10.16 @mui/system: 5.10.16 @mui/types: 7.2.2 @mui/utils: 5.10.16 @types/react: ^17.0.44 => 17.0.52 react: ^17.0.2 => 17.0.2 react-dom: ^17.0.2 => 17.0.2 typescript: ~4.6.4 => 4.6.4
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 39
- Comments: 59 (24 by maintainers)
Commits related to this issue
- fix issue of https://github.com/mui/material-ui/issues/35287 — committed to NaClYen/badminton by NaClYen 2 years ago
It seems that the issue is caused by a type mismatch between @types/react@17 and @types/react@18. As a workaround, you can add the following module augmentation code to your projects:
Solving this “properly” is a pickle, to be honest. Apparently DefinitelyTyped can’t add these two fields to React 17 typings, because they are only supported in 18. We may have to live with this workaround for longer, unfortunately.
Could you upgrade
@types/reactto latest version (v18.0.25) and check if the error is gone? TheseonResizeandonResizeCapturewere added recently in https://github.com/DefinitelyTyped/DefinitelyTyped/pull/63076. My guess is that because of this change MUI only works now with@types/react: ^18.0.25.Definitely wasn’t expecting a patch release to blow up my build… getting this:
We’re not planning to remove support for React 17.
There is a more elegant solution to this problem if you don’t want to declare the module globally.
steps:
declare an explicitly “undefined” values
<Popper {...props} nonce={undefined} onResize={undefined} onResizeCapture={undefined}>in the typescript configuration (tsconfig), add the option => “skipLibCheck”: true.
{ "compilerOptions": { ...otherProps, "skipLibCheck": true }, }just before that, read in the documentation what this property (skipLibCheck) does exactly. I always use this option, so it’s not a problem for me.
BINGO
will mitigate the issue until future fix 😉
Although this might throw in your tests:
😕
Should react 17 be removed from supported versions? Or this workaround (https://github.com/mui/material-ui/issues/35287#issuecomment-1337250566) should be added to mui code?
To reiterate for those who can upgrade: it works on React 18 (18.2.0) along with the latest version of @types/react (18.0.26)
I have the same issue on
PopperandTimelinecomponents after updating Mui packages to latest version:same Typescript error:
Type '{ children: Element[]; sx: { p: number; }; }' is missing the following properties from type 'Pick<TimelineProps, "classes" | "title" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | ... 252 more ... | "onResizeCapture">': nonce, onResize, onResizeCaptureSame here, works fine with React 18.2.0 and @types/react 18.0.26. Thanks @kurtwaldowski-echelon
Tagging @mui/core since it looks like a high priority issue. I am not certain if it’s related to #35273. Also not sure what’s the fix but I think we need to support latest version of
@types/reactfor React 17 as well. It would be compatible for MUI users using React 17.Just upgraded to
"@mui/material": "5.11.9"- still having this issue.Hello, I have quickly install it and run
npm run type-checkin my project. It works, doesn’t appear any type check in Popper element like before. Thank you!My version of react is : 17.0.2
@eps1lon How about this? https://github.com/xandris/mui-35287
Technically it may work, but you’d get types for a library you don’t use, which may be confusing at best (or you won’t be able to type-check a valid program). The workaround I proposed also introduces attributes that don’t exist at runtime, but it only does it for these two attributes. I don’t know how many differences are there between types of React 17 and 18, but I bet there are more than just these two attributes.
@eps1lon, as a maintainer of React types, do you have any ideas on how to best resolve this issue?
Just to help ^ this also occurs on react 18 unless using the latest react/types - upgrading that removed this for me
I understand it occurs only when using React 17, right? I wasn’t able to reproduce it using 18 (https://codesandbox.io/s/agitated-mestorf-eheb0b?file=/src/App.tsx).
I’m looking into it.
It’s just been released in https://github.com/mui/material-ui/releases/tag/v5.11.8
Works for me with
react v17.0.2! Great job!Please don’t remove React 17. It’s complex enough to migrate a bigger project to MUI 5, enforcing a major version upgrade on React renders gentle migration impossible.
@IdoiaRojo If you don’t use
Popper, this also happens onTimelineand probably other components though.The
Pick<>comes from React types (PropsWithoutRef is defined as such), and we have no control over its shape. However, its possible to specify the return type without usingPropsWithoutRef, which is what I’m doing in #36013Thanks, the new commit also looks good to me. At least doesn’t make any problems for the build.
I made some additional changes. Could you please once again verify the build? The latest bits are available at https://pkg.csb.dev/mui/material-ui/commit/ff29f383/@mui/material
@MartinYankovPP once the PR is approved, I’ll merge it, and it’ll land in the next release. We usually release new versions on Mondays, so there’s a chance it’ll be the next one.
Looks good in our project. We’re using
react v17.0.2as well. I am a colleague of @mbmx10I also wasn’t able to fix the problem with @types/react 18.0.26 at first but knowing that the TS compiler in VS Code is stubborn at times I restarted VS Code and the problem has gone now.
I can’t confirm that unfortunately. I am using React 18.2.0 and @types/react 18.0.26 and the problem is still present