-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[TypeScript / Next.js Example] Link component not compatible with latest alpha #22450
Comments
@piehouserat Do you have reproduction we can look at? (For instance, we need the exact versions of the dependencies) |
+1 based on the feedback to #22452. Repro is here: https://codesandbox.io/s/infallible-forest-65g4d?file=/src/Link.tsx Opening a terminal window and running
|
FYI - looks like this issue exists all the way back to |
I can't observe the issue. Is it possible a release patched it? |
Guys I had some more time on this, bumped all packages to latest and the problem still exists. To prove that it was unrelated to my own code I cloned the latest Out of the box, the ref prop is underlined in red on line 56 with the same error as before. |
@oliviertassinari can we please re-open this, the issue definitely exists and can be observed by simply looking at the example mentioned above |
@piehouserat I can't reproduce with v5: https://github.com/mui-org/material-ui/tree/next/examples/nextjs-with-typescript. |
@oliviertassinari this is so weird, I've attached a screenshot of what I see Is there any way this could be environment related? Only thing of note is that I am on the macOS Big Sur beta although I can't see how this would affect things |
@oliviertassinari It does reproduce locally with v5 example as well, but the curl command refers to master branch. It should be:
As a workaround you can silence it with: |
This comment has been minimized.
This comment has been minimized.
Hey @oliviertassinari you are right, it does fix it... feeling so dumb now 🤪 |
This should close? 🤔 |
@vicasas I think that we can still remove the diff --git a/docs/src/modules/components/Link.tsx b/docs/src/modules/components/Link.tsx
index 16c3ee49b9..91c9cb5d61 100644
--- a/docs/src/modules/components/Link.tsx
+++ b/docs/src/modules/components/Link.tsx
@@ -67,14 +67,14 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(function Link(props,
if (isExternal) {
if (noLinkStyle) {
- return <a className={className} href={href as string} ref={ref as any} {...other} />;
+ return <a className={className} href={href as string} {...other} ref={ref} />;
}
return <MuiLink className={className} href={href as string} ref={ref} {...other} />;
}
if (noLinkStyle) {
- return <NextLinkComposed className={className} ref={ref as any} to={href} {...other} />;
+ return <NextLinkComposed className={className} to={href} {...other} ref={ref} />;
}
let linkAs = linkAsProp || (href as string); But I don't know why, maybe @eps1lon has an explanation. |
Could somebody give me a summary with reproduction what the problem here is? I'd usually wouldn't question the type-checker if I can remove an unsound cast such as |
@eps1lon The simplest way to reproduce is to remove the any: diff --git a/docs/src/modules/components/Link.tsx b/docs/src/modules/components/Link.tsx
index 16c3ee49b9..51830fe7a7 100644
--- a/docs/src/modules/components/Link.tsx
+++ b/docs/src/modules/components/Link.tsx
@@ -67,14 +67,14 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(function Link(props,
if (isExternal) {
if (noLinkStyle) {
- return <a className={className} href={href as string} ref={ref as any} {...other} />;
+ return <a className={className} href={href as string} ref={ref} {...other} />;
}
return <MuiLink className={className} href={href as string} ref={ref} {...other} />;
}
if (noLinkStyle) {
- return <NextLinkComposed className={className} ref={ref as any} to={href} {...other} />;
+ return <NextLinkComposed className={className} ref={ref} to={href} {...other} />;
}
let linkAs = linkAsProp || (href as string); and run: cd docs
yarn typescript it will fail with:
|
@oliviertassinari That's our internal implementation though. I don't think we need an issue for every internal instance where we cast to any. Either way, this is a known issue with TypeScript: microsoft/TypeScript#30748 |
@eps1lon True. However, we use the same one for the public Next.js TypeScript example. Same problem, same reproduction, same proposed fix: |
It seems that we can solve the root issue in #24901. |
Using TS 4.x, Material UI latest alpha and next.js latest I am getting the following error in the Link.tsx component
the error comes when assigning the innerRef to the ref prop of the NextComposed component
I've only been working with TS for a few weeks now so not able to figure out the correct typings required here.
Any help would be appreciated
The text was updated successfully, but these errors were encountered: