-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
React, JSX and refs #30748
Comments
Yep, it's a long-standing issue in TypeScript. We were able to avoid it for the most part back when the only typesafe refs would be functions, because there is a hack we can use to get TypeScript to treat function parameters as bivariant; but there is no way to tell TypeScript that the "ref" prop actually is contravariant ( I wrote about it in #10717 (comment) but issues about that go as far back as #1394 |
TypeScript Version: 3.4.0-dev.201xxxxx
Search Terms:
react, ref
Code
Expected behavior:
Actual behavior:
Playground Link:
https://github.com/eps1lon/typescript-react-ref-issue
Related Issues:
#16019
I suppose the main issue is how react handles refs. Since react never reads the
current
value it's perfectly fine to pass a less specific type to theref
attribute. I'm not sure if we can express this behavior with types, it is a current limitation that should be fixed or if this is working as intended.The text was updated successfully, but these errors were encountered: