-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Fixes #8657: Handles union typed React component. #8674
Conversation
Hi @evansb, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! TTYL, MSBOT; |
@evansb, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR. |
This doesn't seem like the right approach. What if you had a property of type |
You are right, I should've raised the error as soon as a type doesn't have constructor/call signature instead. Anyway this is still pretty much WIP and doesn't solve the issue quite yet, we will have another problem with the different return type of At the moment |
I think I'm done, would you mind reviewing it? @RyanCavanaugh See description for patch summary |
Can you split out the test so there's a non-erroring test that shows the behavior you're trying to enable? When there's an error we don't generate a type baseline so it's harder to confirm the right thing is happening. |
👍 |
thanks! |
'Bug' or 'Accepting PRs' or is in the Community milestone
master
branchjake runtests
locallyFixes #8657
This pull request handles special case of union typed React component, namely
type U = React.StatelessComponent<any> | React.ComponentClass<any>
. SinceStatelessComponent
has call but no signature andComponentClass
has no call signature but no construct signature, the union between these two will result in a type with no call or construct signature.Previously
<U />
will fail because the type checker cannot find any call/construct signature on it, which is a false negative.This patch handles union typed React component separately: we first unfold the type of
U
and apply the old construct/call signature + return type check.This involves refactoring JSX Element type resolver to a new function
getResolvedJsxType
so that it can be applied recursively to each member of the union types.Evan Sebastian.