-
-
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
Link Component has bad typings in V4 #15299
Comments
|
All of the forward refd types are wrong bc they use the wrong withStyles types AND they type it as a regular component. You can fix it by creatinf your own version where its like React.forwardRef(function Link(props: LinkProps, ref){ etc |
What would be the correct type? Could you add some examples that should fail/pass in the type checker but are actually sound/unsound?
The type of the component is not part of the public API. Only the props. I'm not sure what you mean by "regular component"? |
@eps1lon - I took a pass at fixing the types, it resolved about 15 TSC errors I was getting for using I'm not entirely sure where to add tests for this, didnt see a .spec.tsx in the Link component (or when those runs), and was unclear about the typescript docs as well. If anyone has thoughts on that or could point me to an example of what to do there, I'm happy to add that. |
When using
"@material-ui/core": "^4.0.0-alpha.7"
and typescript, I can't use a customcomponent
in<Link>
s.Expected Behavior 🤔
I've created a code sample: https://github.com/nmain/link-ts-bug
It is a barebones
create-react-app --typescript
with the minimal changes to illustrate my situation. In it, I have aMyLink
component that simply creates an<a>
and spreads the provided props to it:I want to use that as the
component
for a MUI<Link>
. In MUI v4, I have to useReact.forwardRef
to do that, but it won't pass typechecking:Current Behavior 😯
MyLinkWithoutRefForwarding
causes an error message at runtime as MUI v4 is no longer usingfindDOMNode
.MyLink
, when theas any
typecast is removed, causes a typechecking error:Steps to Reproduce 🕹
https://github.com/nmain/link-ts-bug was created as follows:
Context 🔦
In the real use case that I have extracted this example from,
<MyLink>
does some custom modifications tohref
to work with some legacy ASP.NET routing. As I continue to evolve this project, I hope to have<MyLink>
do some client-side routing instead at some point in the future. Either way, it should be a fully functional stand-in for<a>
.Your Environment 🌎
Package.json deps:
The text was updated successfully, but these errors were encountered: