@@ -9499,34 +9499,6 @@ 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
-
9530
9502
/**
9531
9503
* Given a JSX element that is a class element, finds the Element Instance Type. If the
9532
9504
* element is not a class element, or the class element type cannot be determined, returns 'undefined'.
@@ -9540,11 +9512,43 @@ namespace ts {
9540
9512
return anyType;
9541
9513
}
9542
9514
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
+
9543
9549
// Resolve the signatures
9544
9550
let signatures = getConstructOrCallSignature(valueType);
9545
9551
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));
9548
9552
return unknownType;
9549
9553
}
9550
9554
0 commit comments