-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
fix: update return type for @types/react #13
Conversation
In @types/react version 2.14 (could have started earlier), the return type of PolymorphicForwardRefExoticComponent started being incorrect causing a TS error. When changing it to return React.ReactNode instead of React.ReactElement, it works again.
The pull request may close the #12 |
I wouldn’t recommend using this project anymore, as outlined over here: kripod/react-polymorphic-box#25 (comment) I’d suggest using a render prop instead of @TheWashiba Please be respectful towards OSS contributors. Your behavior is the primary reason I’m tired of maintaining projects like this one. I’m calling this out loud – enough is enough. Feel free to fork the project and create a fix on your own if you want to. People like you made me burn out. I’ve consciously decided to distance myself from OSS due to its adverse effects on mental health. Maintainers don’t own you a single thing, especially considering the fact that you don’t seem to sponsor any of them. |
My apologies @kripod, no disrespect intended here. This finally solved my issue and I was just too hasty to get it merged. Thank you for your contributions, sincerely |
Scratch that, see my next suggestion for a better solution. |
@@ -36,7 +36,7 @@ type PolymorphicExoticComponent< | |||
*/ | |||
<InstanceT extends React.ElementType = T>( | |||
props: PolymorphicPropsWithRef<P, InstanceT>, | |||
): React.ReactElement | null; | |||
): React.ReactNode | null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
): React.ReactNode | null; | |
): ReturnType<React.FunctionComponent>; |
Found this works better, with different combinations of TS and React types versions, this library wants to always return whatever React itself returns.
Closing because no review activity |
Issue
In
@types/react
version 2.14 (could have started earlier), the return type ofPolymorphicForwardRefExoticComponent
started being incorrect causing a TS error.Example code
Example error
Proposed solution
When changing it to return
React.ReactNode
instead ofReact.ReactElement
, the type error goes away. I've tested this in our internal codebase and everything seems to work as expected.