Fixes #8657: Handles union typed React component.#8674
Fixes #8657: Handles union typed React component.#8674mhegazy merged 7 commits intomicrosoft:masterfrom
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
masterbranchjake runtestslocallyFixes #8657
This pull request handles special case of union typed React component, namely
type U = React.StatelessComponent<any> | React.ComponentClass<any>. SinceStatelessComponenthas call but no signature andComponentClasshas 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
Uand apply the old construct/call signature + return type check.This involves refactoring JSX Element type resolver to a new function
getResolvedJsxTypeso that it can be applied recursively to each member of the union types.Evan Sebastian.