-
Notifications
You must be signed in to change notification settings - Fork 30.5k
[react] Change React StatelessComponent return type to ReactNode #25349
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
[react] Change React StatelessComponent return type to ReactNode #25349
Conversation
|
@herrstucki Thank you for submitting this PR! 🔔 @johnnyreilly @bbenezech @pzavolinsky @digiguru @ericanderson @morcerf @tkrotoff @DovydasNavickas @onigoetz @theruther4d @guilhermehubner @JoshuaKGoldberg @jrakotoharisoa - please review this PR in the next few days. Be sure to explicitly select If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead. |
|
@herrstucki The Travis CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! |
|
The tests are failing because of how Typescript resolves JSX element constructors. When you changed I'm not sure why it worked in the first place based on my understanding of the resolution rules for JSX constructors, because the current return type of Maybe one of the TS devs can help out or someone who knows more about the JSX rules in TS 😄 |
|
@herrstucki I haven't seen anything from you in a while and this PR currently has problems that prevent it from being merged. The PR will be closed tomorrow if there aren't new commits to fix the issues. |
|
@herrstucki The Travis CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! |
|
Well, at least the react typings lint fine now but a lot of other packages seem to be broken by this 😥 |
|
Yes, the change to I also can't think of a way this would work with the current JSX constructor rules that Typescript imposes... hmmmmmm 🤔 |
|
Ah, I didn't realize there was already an issue opened in the Typescript repo for this, see microsoft/TypeScript#21699 I don't think that until that is resolved you'd be able to change the return type to |
|
Alright, I’ll close this then. Thanks for your feedback @ferdaber! |
Fixes #18051
The tests in
tsx.tsxfail for some reason I can't explain:ReactNodeis definitely the correct return type for SFCs though (see linked Flow type definition). I've confirmed this in a real application. Also, the return type ofComponent.render()already isReactNode– SFCs aren't different in this regard.Use a meaningful title for the pull request. Include the name of the package modified.
Test the change in your own code. (Compile and run.)
Add or edit tests to reflect the change. (Run with
npm test.)Follow the advice from the readme.
Avoid common mistakes.
Run
npm run lint package-name(ortscif notslint.jsonis present).Provide a URL to documentation or source code which provides context for the suggested changes: https://github.com/facebook/flow/blob/a38fec68986f66d2d189556988d6c97cbcc1458b/lib/react.js#L132