-
Notifications
You must be signed in to change notification settings - Fork 13k
Improve JSX invalid children type error #52105
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
Conversation
* Assumes `target` type is assignable to the `Iterable` type, if `Iterable` is defined, | ||
* or that it's an array-like type, if `Iterable` is not defined. | ||
*/ | ||
function elaborateIterableOrArrayLikeTargetElementwise( |
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.
This function was copied from the existing elaborateElementwise
function, and then modified to work with a target that is iterable or array-like. Some parts of the elaboration were removed because I figured they didn't apply in this specific case, and some were adapted.
@typescript-bot perf test this faster |
Heya @gabritto, I've started to run the diff-based user code test suite on this PR at ee4ea51. You can monitor the build here. Update: The results are in! |
Heya @gabritto, I've started to run the diff-based top-repos suite on this PR at ee4ea51. You can monitor the build here. Update: The results are in! |
Heya @gabritto, I've started to run the abridged perf test suite on this PR at ee4ea51. You can monitor the build here. Update: The results are in! |
@gabritto Here are the results of running the user test suite comparing Everything looks good! |
@gabritto Here are the results of running the top-repos suite comparing Everything looks good! |
@gabritto Here they are:Comparison Report - main..52105
System
Hosts
Scenarios
Developer Information: |
Fixes #48796.
The original error elaboration tried to detect whether a component expected multiple children or just one by checking if the types were array-like. However, the type definition of
ReactNode
, more specifically of itsReactFragment
component, were updated to useIterable<ReactNode>
. So that meant that, if a component expected children of typeReactNode
(orReactFragment
, we'd think it was expecting a single child, becauseIterable<ReactNode>
is not an array-like type, so the error message reflected that, leading to TS confusingly saying the component expected a single child even when an array of children of the correct type would be accepted.I updated that error elaboration to use assignability to
Iterable
(when this type is defined) as the way to differentiate between components expecting a single child or multiple children. I also had to further change the error elaboration used to account for an use ofIterable
.