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
[MUI v5] Type Error when using Icons from @mui/icons-material #18018
Comments
I've been playing around to see if I could come up with a fix for this before I submit a PR. The type for the
If I change this to be like this the errors for away: export type IconComponent =
| ComponentType<{
fontSize?: 'default' | 'small' | 'large' | undefined;
}>
| ComponentType<{}>; But I think this might be very naive on my part? |
This is a good discovery. I ran into a similar issue when hacking on MUI v5 type SidebarItemBaseProps = {
icon: typeof SvgIcon;
text?: string`
... We might want to rethink the
|
Yeah, I'm open to any suggestions with this one. But I do think we want to try and resolve this soon as it's the one that everyone who upgrades to MUI v5 will run in to |
yes, you are right! it's not great. hopefully I have some time tommorrow to look at this & related MUI 5 issues |
I think we're generally open and grateful for the help investigating and suggesting a fix. I know that the IconComponent was added quite some time back because of similar type issues and we wanted to narrow the type to the absolute minimum that we needed at the time to avoid minor inconsequential type differences causing issues. Now, it seems like even this very narrow slice of the type still can cause issues :) Sidestepping it with some clever typeof sounds compelling - if it actually works in the mixed-mui-major case etc. |
added a PR with a possible solution, which worked for me - happy about feedback |
Sadly it seems this error has not been resolved or has cropped up in some other variation. This came up again recently in this Discord thread: https://discord.com/channels/687207715902193673/1192389833235120239. I took a run at migrating the Demo site as that needs to happen eventually anyway and ran into the error there as well: backstage/demo#212 |
What's interesting is that the original error message in this Issue is only there once but the others are now just this:
See the detailed errors here: https://github.com/backstage/demo/actions/runs/7425731911/job/20207991237?pr=212 |
In the process of upgrading and running into the same issue as well.
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This needs to be fixed as it's blocking clean migrations to MUI v5 |
I tried migrating to MUI v5 today, before upgrading backstage to 1.24.0. I've resolved all other issues, but stuck on this one. If there's any workaround available, please share. For now, I'm postponing MUI v5 migration in our instance for later |
we do like this.
so you get like
or
|
📜 Description
When upgrading to MUI v5 we are getting a type error when using Icons from
@mui/icons-material
. We see this in the following places:icon
prop of theSidebarItem
,SidebarSubmenuItem
, andMyGroupsSidebarItem
componentsUNSTABLE_extraContextMenuItems
prop of theEntityLayout
componenticons
section ofcreateApp
in theApp.tsx
The error is:
👍 Expected behavior
You should be able to use icons from
@mui/icons-material
without any type errors👎 Actual Behavior with Screenshots
We get this error:
👟 Reproduction steps
To keep things simple I'm going to base this on the main Backstage repo but you can easily do the same with a fresh instance created with
npx @backstage/create-app@latest
"@mui/icons-material": "^5.11.16"
to thepackage/app/package.json
yarn install
packages/app/src/components/Root/Root.tsx
change this importimport HomeIcon from '@material-ui/icons/Home';
to be like thisimport HomeIcon from '@mui/icons-material/Home';
yarn tsc
Notice: You'll get a type error
📃 Provide the context for the Bug.
While upgrading to MUI v5 we ran into a number of cases like this. Now we can work around this by adding
as IconComponent
but we feel this should probably been something that is resolved in the Backstage itself as it would make this upgrade smoother and with less manual changes🖥️ Your Environment
This really isn't an environment specific issue more around the usage of
@mui/icons-material
👀 Have you spent some time to check if this bug has been raised before?
🏢 Have you read the Code of Conduct?
Are you willing to submit PR?
Yes I am willing to submit a PR!
The text was updated successfully, but these errors were encountered: