Material-ui: Typescript ForwardRef / No overload matches this call

Created on 24 Nov 2019  路  7Comments  路  Source: mui-org/material-ui

  • [x ] The issue is present in the latest release.
  • [ x] I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 馃槸

I am following the composition guide on https://material-ui.com/guides/composition/ to adapt a list link to a router, I'm trying to follow the instructions and make it work with typescript but the component property is throwing errors, spent a few hours on it and I cannot work out what is causing the issue.

Expected Behavior 馃

The component property should not throw errors, unexplained "No Overload Matches This Call".

Steps to Reproduce 馃暪

https://codesandbox.io/s/create-react-app-with-typescript-orwte?fontsize=14&hidenavigation=1&theme=dark

Steps:

If you look at this function, the component property on ' is throwing an error:


function ListItemLink(props: ListItemLinkProps) {
  const { primary, to } = props;

  const renderLink = React.useMemo(
    () =>
      React.forwardRef(function f(linkProps) {
        return <Link to={to} {...linkProps} />;
      }),
    [to]
  );

  return (
    <li>
      <ListItem component={renderLink}>
        <ListItemText primary={primary} />
      </ListItem>
    </li>
  );
}

Context 馃敠

Would like to use react-router with typescript and material UI in a performant relatively type safe manner.

Your Environment 馃寧

Windows WSL2 Ubuntu Node10

| Tech | Version |
| ----------- | ------- |
| Material-UI | v4.7.0 |
| React | 16.12 |
| Browser | |
| TypeScript | 3.7.2 |
| etc. | |

question typescript

Most helpful comment

The main issue is that you're not providing any type arguments to React.forwardRef.
Here is a working example https://codesandbox.io/s/create-react-app-with-typescript-ojoyh

All 7 comments

Your codesandbox is broken:

You aren't using the ref argument for React.forwardRef
You are using Link outside of a router

@joshwooding so I have tried with the ref and without, I just updated that code pen and I'm getting the same error, and actually adding ref adds the error there, I may be messing this up somehow but this is what I have:

```

function ListItemLink(props: ListItemLinkProps) {
const { primary, to } = props;

const renderLink = React.useMemo(
() =>
React.forwardRef(function f(linkProps, ref) {
return ;
}),
[to]
);

return (





  • );
    }```

    @seandearnaley Have you added the Router too?

    @joshwooding yes, just added to the pen to be sure, note the pen seems to run without error but there are these typescript errors underlined in red for the ref and component,..

    thanks for helping out, I really appreciate it

    @seandearnaley Ill have to download the codesandbox to test it so I鈥檒l do it tomorrow if no one beats me to it!

    The main issue is that you're not providing any type arguments to React.forwardRef.
    Here is a working example https://codesandbox.io/s/create-react-app-with-typescript-ojoyh

    @merceyz that worked great! thank you so much

    Was this page helpful?
    0 / 5 - 0 ratings

    Related issues

    rbozan picture rbozan  路  3Comments

    reflog picture reflog  路  3Comments

    anthony-dandrea picture anthony-dandrea  路  3Comments

    ericraffin picture ericraffin  路  3Comments

    revskill10 picture revskill10  路  3Comments