Skip to content
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

[Material-ui 4] Typescript: component property does not exist on MenuItem #14970

Closed
2 tasks done
sveyret opened this issue Mar 20, 2019 · 17 comments
Closed
2 tasks done
Labels
status: waiting for author Issue with insufficient information typescript

Comments

@sveyret
Copy link
Contributor

sveyret commented Mar 20, 2019

I am testing mui@next. When I try to create a link (through react-router) on a MenuItem, creating a component as the documentation suggests, I have an error saying that porperty 'component' does not exist on type 'IntrinsicAttributes & { action?: ((actions: ButtonBaseActions) => void) | undefined; buttonRef?: ((instance: any) => void) | RefObject | null | undefined; centerRipple?: boolean | undefined; ... 6 more ...; TouchRippleProps?: Partial<...> | undefined; } & { ...; } & { ...; } & CommonProps<...> & Pick<...>'

This was working correctly with mui < v4.0

Note that it seemed to have already appeared and corrected in alpha.3 (#14786)

  • This is not a v0.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Code 🕹

const component:
  | React.ExoticComponent<LinkProps>
  | undefined = React.forwardRef<Link, LinkProps>(
  ({ children, ...props }, ref) => (
    <Link {...props} to="/" ref={ref}>
      {children}
    </Link>
  )
);

function displayMenuEntryContent() {
  return (
    <MenuItem component={component}>
      <ListItemText primary="Home" />
    </MenuItem>
  );
}

// Render
return displayMenuEntryContent();

Your Environment 🌎

Tech Version
Material-UI 4.0.0-alpha.4
React 16.8.4
React router 5.0.0
@types/react 16.8.8
TypeScript 3.3.3333
@sveyret sveyret changed the title Typescript: component property does not exist on MenuItem [Material-ui 4] Typescript: component property does not exist on MenuItem Mar 20, 2019
@oliviertassinari oliviertassinari added status: waiting for author Issue with insufficient information typescript labels Mar 20, 2019
@oliviertassinari
Copy link
Member

@sveyret I can't reproduce the issue. Do you have a reproduction?

@sveyret
Copy link
Contributor Author

sveyret commented Mar 21, 2019

Thank you @oliviertassinari for looking at it.

I did not manage to reproduce in CodeSandbox, so I made a minimal project where the compilation fails because of this issue (see its README in order to see how to use it):
https://github.com/sveyret/issue-mui-14970

Note that it is very strange, because if the <MenuItem> is returned directly by the component (and not by a method), there is no error. It might then be actually a Typescript problem.

@sveyret
Copy link
Contributor Author

sveyret commented Mar 28, 2019

@oliviertassinari I added the yarn.lock file to the project to ensure that versions are the same. I see that the issue is still “incomplete”. Is there anything else I need to provide?

@eps1lon
Copy link
Member

eps1lon commented Mar 28, 2019

@sveyret This should be fixed with #14772 and released in alpha.5. Can you verify if this issue is fixed for you?

@sveyret
Copy link
Contributor Author

sveyret commented Mar 28, 2019

@eps1lon If I didn't do any mistake with my test, this PR does not correct the problem.

@oliviertassinari
Copy link
Member

oliviertassinari commented Mar 28, 2019

does not correct the problem.

👍 or 👎 ?

@sveyret
Copy link
Contributor Author

sveyret commented Mar 28, 2019

👎 Issue is not fixed

@eps1lon
Copy link
Member

eps1lon commented Mar 28, 2019

The issue is the type definition of your component. component is now a discriminant in a union type. It can no longer be all possible values. It's essentially the same as #14971.

You cannot use undefined | ComponentType. You have to use either one.

@Dudrie
Copy link
Contributor

Dudrie commented Mar 28, 2019

I encountered the same issue (even with alpha.5). However, I "fixed" it as follows in VS code:

  1. Updated the typescript version to 3.3.4000 (this implies that typescript is a dependency in package.json or that you use a global version of typescript).
  2. Switch workspace to use this version (instead of 3.3.3 vscode provides).
  3. The error went away.

But, I recogniced something strange along that path: If you follow the steps above and if you switch back to ts 3.3.3 (after the error message disappearing) the error won't come back 😮

@eps1lon
Copy link
Member

eps1lon commented Mar 28, 2019

Updated the typescript version to 3.3.4000 (this implies that typescript is a dependency in package.json or that you use a global version of typescript).

This should be the default case. Every dependency should be listed.

Switch workspace to use this version (instead of 3.3.3 vscode provides).

We need to include this in the issue template. We can only help with error messages that are displayed when building your code (via tsc or webpack). Errors from your IDE depend on your IDE setup.

@sveyret
Copy link
Contributor Author

sveyret commented Mar 28, 2019

@eps1lon Thank you for the information. You can close the issue, then.

@eps1lon eps1lon closed this as completed Mar 28, 2019
@gianlucamateo
Copy link

I am having the same issue when trying to pass a component to the ListItem or MenuItem components.

I am trying to apply this proposed solution [https://stackoverflow.com/a/55693040/11760100](from Stackoverflow), but I am getting both IDE errors and TypeScript errors when trying to compile.

Property 'component' does not exist on type 'IntrinsicAttributes & { action?: ((actions: ButtonBaseActions) => void) | undefined; buttonRef?: ((instance: unknown) => void) | RefObject<unknown> | null | undefined; centerRipple?: boolean | undefined; ... 6 more ...; TouchRippleProps?: Partial<...> | undefined; } & { ...; } & { ...; } & CommonProps<...> & Pick<...>'. TS2322

I am using MUI 4.1.3 with TS 3.5.1

@TeoTN
Copy link

TeoTN commented Jul 28, 2019

Same here with MUI 4.2.1 and TS 3.5.3.
Could you reopen the issue?

@yuvalic
Copy link

yuvalic commented Jul 31, 2019

Same here even with MUI 4.3.1 and TS 3.5.3
help please

@oliviertassinari
Copy link
Member

Do you guys have a reproduction? Could you upvote the issue in this case?

@eps1lon
Copy link
Member

eps1lon commented Jul 31, 2019

Please open a separate issue and follow the template. The original issue was fixed and is concerned with an alpha release which we do not support any longer.

@jankalfus
Copy link

Until PR #16487 is released, there's a workaround if you used a div as component prop previously. Just remove the component completely and replace it by button prop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting for author Issue with insufficient information typescript
Projects
None yet
Development

No branches or pull requests

8 participants