/core dependency on /types ^5.1.0 is too loose
See original GitHub issue@material-ui/core
depends on @material-ui/types@^5.1.0
. The caret means that any 5.x version is allowed. If you actually try to use @material-ui/core
, odd problems manifest.
- The issue is present in the latest release. It’s present in the latest ‘stable’ release 4.11.3
- I have searched the issues of this repository and believe that this is not a duplicate.
Current Behavior 😯
Trying to spread with DateTimePickerProps
from MUI Pickers:
import { DateTimePickerProps } from '@material-ui/pickers';
// Get a DateTimePickerProps from somewhere
const t = null as unknown as DateTimePickerProps;
console.log(
t.InputProps, // This works
{ ...t }.InputProps, // This also works
{ ...{}, ...t }.InputProps, // 'InputProps' does not exist on type ...
);
That third argument to console.log
raises an error at compile time.
Expected Behavior 🤔
The spread should work fine.
Steps to Reproduce 🕹
Steps:
- Open https://codesandbox.io/s/mui-4113-types-dep-problem-8k1xv
- Wait for a moment for codesandbox to install things
- Note the error on the
{ ...{}, ...t }
line - Change the version of
@material-ui/types
inpackage.json
to 5.1.6 and save it - Wait a moment
- Note the error in
index.d.ts
goes away
Context 🔦
I’m trying to merge the picker props from our React code with props from Formik before passing them to MUI Pickers. I think any new install of MUI 4.x (without a lockfile) will encounter this problem.
The root cause, I believe, is that my project depends on @material-ui/core
4.11.3, which in turn depends on @material-ui/types
^5.1.0, which resolved to 5.1.7. This is because the type DateTimePickerProps
ultimately uses types from OverridableComponent.d.ts
, which tries to import Omit
from @material-ui/types
. However, as of 5.1.7, Omit
was renamed to DistributiveOmit
.
I think it’s a TypeScript bug to raise the error that it did, since the problem is actually that the type definitions in use are unsound, but I think there’s also a problem here in Material UI. The range on the dependency should probably be 5.1.0 - 5.1.6
, or OverridableComponent.d.ts
should change to import DistributiveOmit
. I’ve verified that either change fixes the TypeScript error.
Your Environment 🌎
`npx @material-ui/envinfo`
System:
OS: macOS 11.2.1
Binaries:
Node: 15.10.0 - /usr/local/bin/node
Yarn: 2.4.0-git.20210302.hash-04227fe7 - /usr/local/bin/yarn
npm: 7.6.0 - /usr/local/bin/npm
Browsers:
Chrome: 88.0.4324.192
Edge: Not Found
Firefox: 84.0.2
Safari: 14.0.3
I’m using TypeScript 4.2.2. I can’t post our tsconfig, but the repro in codesandbox.io should suffice.
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (9 by maintainers)
Top GitHub Comments
Should be fixed in
@material-ui/core@4.11.4
We should fix the prior mistake and bump it to v6. Trying to think of a way to prevent these mistakes in the future. Will wait for another incident to come up with a good solution.