-
Notifications
You must be signed in to change notification settings - Fork 929
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 compiler error with ref passed from getInputProps to component using a forwardRef #718
Comments
I looked into the codesandbox but I don't see any error with ref. Instead I see one with the you are using, that it does no accept onKeyUp (or onKeyDown for instance). If you cast it to any Try to fix it at your end or change the codesandbox with the relevant error. Thank you! |
@silviuavram the error is there, it says Typing the return value of the function as |
I'm also getting this error and the 'error with ref' message is clear in the codesandbox repro that @fenech created. |
I ran into this as well, it seems to be caused by components that are forwarding the ref. I'm assuming styled does this. I was able to replicate it just creating a super simple component that wraps a std Looking at the react types for 16.9 there are two ref types:
and the typing for the InputProps loads the React.HTMLProps which uses
It looks like what happening is that the typing for
All that being said, I'm not sure how to fix it. Edit, overriding the types as a temporary fix works:
|
Can someone create a PR if there is a fix? Please also look at the useSelect and useCombobox typings maybe they need to be fixed as well. Thanks! |
Similarly, to get around this issue I've been creating new types that look like this: export type IntrinsicDiv = JSX.IntrinsicElements['div'] & { ref?: Ref<HTMLDivElement> }; |
I fix up the ref type like this, but it feels wrong:
|
|
I'm trying the following:
after declaring:
but I still get the same error:
Does someone have any idea how to fix it? I'm using React 17.0.2 and downshift 6.1.7 and material-ui 5.0.0 |
downshift
version: 3.2.10node
version: v11.15.0npm
(oryarn
) version: 6.7.0react
version: 16.8.4styled-components
version: 4.3.1Relevant code or config
What you did: Attempted to pass a custom
getInputProps
to a component which implements a forward ref (in this case, to an<input>
element).What happened: A compiler error from TypeScript:
Reproduction repository: https://codesandbox.io/s/loving-diffie-njech
Problem description: Type of
ref
is incompatible, even though the component appears to behave correctly with the forwarded ref.Suggested solution: Change the type definitions to (optionally?) remove the
LegacyRef
part.The text was updated successfully, but these errors were encountered: