-
-
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] type for ref in <Input/> not sufficiently strict #15072
Comments
It is currently typed as That whole logic can be simplified once v4 lands. The longterm goal is to drop |
Thanks for the quick response @eps1lon. Could you provide a code snippet for
I'm not sure if you mean fork a copy of |
You only have to fork the declaration for "paths": {
"@material-ui/core/Input": ["path/to/forked/Input"]
} You have to be aware though that the instance in |
Thanks @eps1lon!
From what I can tell, you want to handle two types?
I don't think I can be precise about the |
That helps but it's not necessarily true if another component is used via |
Thanks! I don't have a lot of context about the intended use case for
Do you have a list of |
I'll double checked with the code and we require a So |
@tianhuil There is a bigger picture issue when typing refs too strict. What happens is that everybody who only cares about In the current state of TypeScript we can't offer a sound ref type. Soundness is the responsibility of the type user e.g. in this case you would have to declare your ref as You can check out https://github.com/eps1lon/typescript-react-ref-issue/blob/626f5197601c35a13e1207a8f4ab7e029454ecb6/index.tsx for a better overview what's currently accepted and rejected by typescript. |
For components with generic props we infer the exact For a more detailed explanation see #15199. Removing this from the v4 milestone until we get better types for refs i.e. write-only or configurable variance or a better solution is proposed. |
Closing as not actionable for us. For more context see #15199. |
The type for
ref
inInput
is too general. It only requires (among other things)React.RefObject<any>
. But the equivalent requirement for<input> is
React.RefObject`.Expected Behavior 🤔
In the following app, the poorly typed
myRef
does not generate an error when passed to<Input/>
but does generate a type error when passed to<input/>
Current Behavior 😯
It should generate an error on both
<Input/>
and<input/>
. This would be helpful to so typechecking can help automatically check for expressions likemyRef.current.value
in subsequent usage.Steps to Reproduce 🕹
Link: clone this repo and run
npm i
. You'll observe the error inApp.tsx
.Context 🔦
This would be helpful to so typechecking can help automatically check for expressions like
myRef.current.value
in subsequent usage.Perhaps related to #10750
Your Environment 🌎
The text was updated successfully, but these errors were encountered: