Skip to content

Strongly typecheck unions of intrinsic tag names #28557

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

Merged

Conversation

weswigham
Copy link
Member

This comment mentioned the change. The exact example given with a and div tags won't work - they have props types of DetailedHTMLFactory<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement> and DetailedHTMLFactory<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, respectively - neither one of which is a subtype of the other, so no union call can be made. However, this does allow similar elements to coexist in a union, eg h1 and h2 or caption and code. Once we have a general fix for #7294, this change should also allow jsx intrinsics to light up alongside that.

The change itself is just moving the StringLiteral and String tag type handling logic inside getUninstantiatedJsxSignaturesOfType, so it applies to union members in addition to the top-level type.

!!! error TS2339: Property 'h1' does not exist on type 'JSX.IntrinsicElements'.
~~~~~~~~~
!!! error TS2604: JSX element type 'CustomTag' does not have any construct or call signatures.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously we'd bail early rather than issuing both messages here. I could probably contort it a bit to only issue one of the two errors; but I feel like having both is slightly more descriptive, actually.

@weswigham weswigham merged commit b90d291 into microsoft:master Nov 15, 2018
@weswigham weswigham deleted the allow-unions-of-jsx-intrinsics branch November 15, 2018 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants