You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TS Error Type 'ForwardRefExoticComponent<Omit<TextProps<ElementType<any>>, "ref"> & RefAttributes<unknown>>' is not assignable to type 'TextComponent'. #7
Firstly, thank you for an amazing and very thorough tutorial on logrocket!
I've followed the tutorial, and had this error on the Text compomnent:
Type 'ForwardRefExoticComponent<Omit<TextProps<ElementType<any>>, "ref"> & RefAttributes<unknown>>' is not assignable to type 'TextComponent'.
Type 'ReactNode' is not assignable to type 'ReactElement<any, string | JSXElementConstructor<any>> | null'.
Type 'undefined' is not assignable to type 'ReactElement<any, string | JSXElementConstructor<any>> | null'.(2322)
Type 'ForwardRefExoticComponent<Omit<TextProps<ElementType<any>>, "ref"> & RefAttributes<unknown>>' is not assignable to type 'TextComponent'.
Type 'ReactNode' is not assignable to type 'ReactElement<any, string | JSXElementConstructor<any>> | null'.
Type 'undefined' is not assignable to type 'ReactElement<any, string | JSXElementConstructor<any>> | null'.ts(2322)
``
I think that's because React.forwardRef() method's return type is overriden. I'm not 100% sure but maybe you can type the component like this so that you also get defaultProps and propTypes in case you need.
Activity
hungify2022 commentedon Oct 30, 2023
Due to the Typescript version.
An error appears on
^4.9.5but^4.7.4doesn't.Someone Typescript expert can resolve that.
itisnas commentedon Nov 5, 2023
Did anyone solve this?
cyhfe commentedon Nov 27, 2023
ozguruysal commentedon Dec 5, 2023
Change the return type as in the comment below.
hungify commentedon Dec 14, 2023
It still gives me error.
ozguruysal commentedon Dec 15, 2023
@hungify not sure. I don't see any error when I make that change. Here's the playground link with the update I suggested above.
hungify commentedon Dec 16, 2023
@ozguruysal
Thank you!
But I have a new problem, how to resolve it
Here is my idea
ozguruysal commentedon Dec 16, 2023
I think that's because
React.forwardRef()method's return type is overriden. I'm not 100% sure but maybe you can type the component like this so that you also getdefaultPropsandpropTypesin case you need.