material-ui: [TypeScript / Next.js Example] Link component not compatible with latest alpha
Using TS 4.x, Material UI latest alpha and next.js latest I am getting the following error in the Link.tsx component
if (naked) {
return (
<NextComposed
className={className}
ref={innerRef}
href={href}
{...other}
/>
)
}
the error comes when assigning the innerRef to the ref prop of the NextComposed component
Type '((instance: HTMLSpanElement | null) => void) | RefObject<HTMLSpanElement> | (((instance: HTMLAnchorElement | null) => void) & ((instance: any) => void)) | ... 4 more ... | undefined' is not assignable to type '((instance: HTMLAnchorElement | null) => void) | RefObject<HTMLAnchorElement> | null | undefined'.
Type 'RefObject<HTMLSpanElement>' is not assignable to type '((instance: HTMLAnchorElement | null) => void) | RefObject<HTMLAnchorElement> | null | undefined'.
Type 'RefObject<HTMLSpanElement>' is not assignable to type 'RefObject<HTMLAnchorElement>'.
Type 'HTMLSpanElement' is missing the following properties from type 'HTMLAnchorElement': charset, coords, download, hreflang, and 21 more.
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
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 18 (13 by maintainers)
Hey @oliviertassinari you are right, it does fix it… feeling so dumb now 🤪 I’ll be happy to push a PR for that 🙂
+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
npx tsc --noEmitwill spit out the error.@vicasas I think that we can still remove the
anywith in the example:But I don’t know why, maybe @eps1lon has an explanation.
I can’t observe the issue. Is it possible a release patched it?
FYI - looks like this issue exists all the way back to
"@material-ui/core": "5.0.0-alpha.1"on my local setup.