Skip to content
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

JSX uses mixed signatures and union sigs use subtype on partial match #28141

Merged
merged 2 commits into from
Oct 26, 2018

Conversation

weswigham
Copy link
Member

Fixes #27948 in the general case where the union elements are like ComponentType - very similar signatures in each union member.

function checkJsxReturnAssignableToAppropriateBound(isSFC: boolean, elemInstanceType: Type, openingLikeElement: Node) {
if (isSFC) {
function checkJsxReturnAssignableToAppropriateBound(refKind: JsxReferenceKind, elemInstanceType: Type, openingLikeElement: Node) {
if (refKind === JsxReferenceKind.Function) {
const sfcReturnConstraint = getJsxStatelessElementTypeAt(openingLikeElement);
if (sfcReturnConstraint) {
checkTypeRelatedTo(elemInstanceType, sfcReturnConstraint, assignableRelation, openingLikeElement, Diagnostics.JSX_element_type_0_is_not_a_constructor_function_for_JSX_elements);
Copy link

@Jessidhia Jessidhia Oct 26, 2018

Choose a reason for hiding this comment

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

(note) as of React 16, components are also allowed to return number / string / boolean (in other words, anything other than undefined, symbol or a non-Element, non-Array object), but at least TS@latest will reject SFC which include those return types. It does validate with classes, just not functions.

If fixed this probably goes in another PR though.

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.

3 participants