-
Notifications
You must be signed in to change notification settings - Fork 12.8k
TS 3.2 breaks type-unioned component support under certain circumstances #28795
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
Comments
This may explain this one: #28768 (comment) |
Thanks for the link @rhys-vdw - that is indeed the case. |
I'm going to mark this as a duplicate of #7294 - go chime in how important that is there, thanks~ |
@weswigham I'm not sure how it can be the same problem. #7294 has been an issue since 2016, whereas the issue I'm describing only began with 3.2+. |
With 3.2 we merged jsx resolution and normal call resolution. (Previously they were separate but similar) To deal with unions, jsx call resolution was doing some unsafe operations that could poison some caches with invalid types and had been the source of a fair set of other bugs in the jsx implementation, especially surrounding generics. We do intend to fix it - I'm just saying we already have a more general issue tracking the problem, since the problem extends beyond jsx tags to all kinds of calls. |
This issue has been marked as a duplicate and has seen no activity in the last day. It has been closed automatic house-keeping purposes. |
@weswigham This issue persists in 3.3.0-rc. Is this still a dupe of #7294? That one is closed and supposed to be fixed in 3.3. |
Do |
Yep, they both have generic arguments. Would it be appropriate to reopen this issue then? Or is there another issue tracking this, or a workaround for now? Fingers crossed for a workaround for now at least because my team is pinned to 3.1.x until we can resolve it. |
Also waiting at least for work around, although there is always retreat to typecast. |
Can we reopen this issue? The related ticket is closed, but this problem still persists in 3.4.x |
I'm seeing a very similar issue as well with I have a union like the following: type ComponentUnion =
| React.Component<SomePropType>
| React.FunctionComponent<SomePropType>; This fails with the above error. Removing the union and using ComponentUnion as just a type alias for one works as expected. |
Since it is a class component, it should be declared with |
I still routinely run into this. |
TypeScript Version: 3.3.0-dev.20181129
Code
ex.tsx:
package.json:
tsconfig.json:
Expected behavior:
Successful compilation.
Actual behavior:
Notes:
This works with TypeScript 3.1.x, but breaks with 3.2.0+. I am not clear on why certain types work and certain types do not, but I imported the React Router types because they definitely break. I tried creating a test
ComponentA
andComponentB
with a render function that returns null, but using a union oftypeof ComponentA | typeof ComponentB
compiles successfully for some reason.The text was updated successfully, but these errors were encountered: