Skip to content

Commit 668e252

Browse files
committed
Requires the construct/call signature for each type in the union instead of whole.
1 parent f04d28d commit 668e252

File tree

1 file changed

+34
-30
lines changed

1 file changed

+34
-30
lines changed

src/compiler/checker.ts

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9499,34 +9499,6 @@ namespace ts {
94999499
return links.resolvedSymbol;
95009500
}
95019501

9502-
/**
9503-
* Given a type, resolve its constructor signatures.
9504-
* If no construct signatures, call signatures are resolved.
9505-
* If the type is a union type, recursively resolve the signatures using
9506-
* the same method.
9507-
* Return collected construct/call signature.
9508-
*/
9509-
function getConstructOrCallSignature(type: Type): Signature[] {
9510-
if (type.flags & TypeFlags.Union) {
9511-
let signatures: Signature[] = [];
9512-
forEach((<UnionOrIntersectionType> type).types, (childType) => {
9513-
let childSignatures = getConstructOrCallSignature(childType);
9514-
forEach(childSignatures, (signature) => {
9515-
signatures.push(signature);
9516-
})
9517-
})
9518-
return signatures;
9519-
} else {
9520-
let signatures = getSignaturesOfType(type, SignatureKind.Construct);
9521-
if (signatures.length === 0) {
9522-
// No construct signatures, try call signatures
9523-
return getSignaturesOfType(type, SignatureKind.Call);
9524-
} else {
9525-
return signatures;
9526-
}
9527-
}
9528-
}
9529-
95309502
/**
95319503
* Given a JSX element that is a class element, finds the Element Instance Type. If the
95329504
* element is not a class element, or the class element type cannot be determined, returns 'undefined'.
@@ -9540,11 +9512,43 @@ namespace ts {
95409512
return anyType;
95419513
}
95429514

9515+
/**
9516+
* Given a type, resolve its constructor signatures.
9517+
* If no construct signatures, it should have call signature,
9518+
* otherwise it's not a valid React component.
9519+
*/
9520+
function getConstructOrCallSignature(type: Type): Signature[] {
9521+
// If the type is a union type, recursively resolve the signatures.
9522+
if (type.flags & TypeFlags.Union) {
9523+
const signatures: Signature[] = [];
9524+
forEach((<UnionOrIntersectionType> type).types, (childType) => {
9525+
const childSignatures = getConstructOrCallSignature(childType);
9526+
forEach(childSignatures, (signature) => {
9527+
signatures.push(signature);
9528+
})
9529+
})
9530+
return signatures;
9531+
} else {
9532+
const constructSignatures = getSignaturesOfType(type, SignatureKind.Construct);
9533+
if (constructSignatures.length === 0) {
9534+
// No construct signatures, try call signatures
9535+
const callSignatures = getSignaturesOfType(type, SignatureKind.Call);
9536+
if (callSignatures.length === 0) {
9537+
// We found no signatures at all, which is an error
9538+
error(node.tagName, Diagnostics.JSX_element_type_0_does_not_have_any_construct_or_call_signatures, getTextOfNode(node.tagName));
9539+
return [];
9540+
} else {
9541+
return callSignatures;
9542+
}
9543+
} else {
9544+
return constructSignatures;
9545+
}
9546+
}
9547+
}
9548+
95439549
// Resolve the signatures
95449550
let signatures = getConstructOrCallSignature(valueType);
95459551
if (signatures.length === 0) {
9546-
// We found no signatures at all, which is an error
9547-
error(node.tagName, Diagnostics.JSX_element_type_0_does_not_have_any_construct_or_call_signatures, getTextOfNode(node.tagName));
95489552
return unknownType;
95499553
}
95509554

0 commit comments

Comments
 (0)