Skip to content
Advertisement

Typescript: How to type ForwardRefExoticComponent + ComponentType

I am trying to type a Component prop that could accept both:

JavaScript

As well as something more custom:

JavaScript

So, I tried:

JavaScript

But when trying to set a ref, I get:

JavaScript

Then I tried:

JavaScript

But in this case, when trying to pass RN.TextInput as prop, I get:

JavaScript

Here is a sandbox showing the issue

Advertisement

Answer

Adding typeof TextInput solve the TS error for me

JavaScript

I think you don’t even need the exotic type because TextInput itself already is capable of receiving a ref

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement