@@ -9499,6 +9499,34 @@ namespace ts {
9499
9499
return links.resolvedSymbol;
9500
9500
}
9501
9501
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
+
9502
9530
/**
9503
9531
* Given a JSX element that is a class element, finds the Element Instance Type. If the
9504
9532
* element is not a class element, or the class element type cannot be determined, returns 'undefined'.
@@ -9512,17 +9540,12 @@ namespace ts {
9512
9540
return anyType;
9513
9541
}
9514
9542
9515
- // Resolve the signatures, preferring constructors
9516
- let signatures = getSignaturesOfType (valueType, SignatureKind.Construct );
9543
+ // Resolve the signatures
9544
+ let signatures = getConstructOrCallSignature (valueType);
9517
9545
if (signatures.length === 0) {
9518
- // No construct signatures, try call signatures
9519
- signatures = getSignaturesOfType(valueType, SignatureKind.Call);
9520
-
9521
- if (signatures.length === 0) {
9522
- // We found no signatures at all, which is an error
9523
- error(node.tagName, Diagnostics.JSX_element_type_0_does_not_have_any_construct_or_call_signatures, getTextOfNode(node.tagName));
9524
- return unknownType;
9525
- }
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));
9548
+ return unknownType;
9526
9549
}
9527
9550
9528
9551
return getUnionType(signatures.map(getReturnTypeOfSignature));
0 commit comments