-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
createRef type for FormControl #3568
Comments
It's whatever the |
Yeah there's definitely an issue with the types for Form.Control |
Ran into the same issue. Until it's fixed, I have found that you can do the following to at least allow your RefObject to maintain a type for usage in the component class:
Note the cast to RefObject<any> inside the ref prop assignment. |
…t-bootstrap#3583, react-bootstrap#3568, react-bootstrap#2781) - Added tests to simple.test.tsx
…react-bootstrap#3568,react-bootstrap#2781) - Added tests to simple.test.tsx
…react-bootstrap#3568,react-bootstrap#2781) - Added tests to simple.test.tsx
This worked for me:
Also had to change |
Does anyone know if https://github.com/react-bootstrap/react-bootstrap/blob/master/types/simple.test.tsx#L211 When I'm usin
|
@Denis-N, how did you import that
?? I think if I had that I'd be able to type this correctly, but I can't find where that's exported. |
I used FYI, the version of react-bootstrap I am using is 4.4.1 |
Doesn't work with
And markup:
As workaround. |
@webcoderkz please try |
@onichandame thanks, it does work. I think react-bootstrap should have some kind of README or guidance on how to type refs with TS. |
In latest release the My solution may not work now. |
@Denis-N have you found a new way?
|
consolidating discussion in #5187 |
Sorry for long wait. Returned to the project today. This works for me now:
|
Wait, my new solution doesn't work today. This one works:
|
I'm using react-bootstrap together with typescript.
What's the proper type in createRef for <Form.Control> element? (instead of any)
private textInput = createRef<any>();
<Form.Control name='textarea_name' as="textarea" ref={this.textInput} />
Once I replace to anything else e.g. , I always see the error in a console like so:
The expected type comes from property 'ref' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<Form<"input">> & Readonly<ReplaceProps<"input", BsPrefixProps<"input"> & FormControlProps>> & Readonly<{ children?: ReactNode; }>...
The text was updated successfully, but these errors were encountered: