diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 580a19f5b2e..c9b69ddd33e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9499,34 +9499,6 @@ namespace ts { return links.resolvedSymbol; } - /** - * Given a type, resolve its constructor signatures. - * If no construct signatures, call signatures are resolved. - * If the type is a union type, recursively resolve the signatures using - * the same method. - * Return collected construct/call signature. - */ - function getConstructOrCallSignature(type: Type): Signature[] { - if (type.flags & TypeFlags.Union) { - let signatures: Signature[] = []; - forEach(( type).types, (childType) => { - let childSignatures = getConstructOrCallSignature(childType); - forEach(childSignatures, (signature) => { - signatures.push(signature); - }) - }) - return signatures; - } else { - let signatures = getSignaturesOfType(type, SignatureKind.Construct); - if (signatures.length === 0) { - // No construct signatures, try call signatures - return getSignaturesOfType(type, SignatureKind.Call); - } else { - return signatures; - } - } - } - /** * Given a JSX element that is a class element, finds the Element Instance Type. If the * element is not a class element, or the class element type cannot be determined, returns 'undefined'. @@ -9540,11 +9512,43 @@ namespace ts { return anyType; } + /** + * Given a type, resolve its constructor signatures. + * If no construct signatures, it should have call signature, + * otherwise it's not a valid React component. + */ + function getConstructOrCallSignature(type: Type): Signature[] { + // If the type is a union type, recursively resolve the signatures. + if (type.flags & TypeFlags.Union) { + const signatures: Signature[] = []; + forEach(( type).types, (childType) => { + const childSignatures = getConstructOrCallSignature(childType); + forEach(childSignatures, (signature) => { + signatures.push(signature); + }) + }) + return signatures; + } else { + const constructSignatures = getSignaturesOfType(type, SignatureKind.Construct); + if (constructSignatures.length === 0) { + // No construct signatures, try call signatures + const callSignatures = getSignaturesOfType(type, SignatureKind.Call); + if (callSignatures.length === 0) { + // We found no signatures at all, which is an error + error(node.tagName, Diagnostics.JSX_element_type_0_does_not_have_any_construct_or_call_signatures, getTextOfNode(node.tagName)); + return []; + } else { + return callSignatures; + } + } else { + return constructSignatures; + } + } + } + // Resolve the signatures let signatures = getConstructOrCallSignature(valueType); if (signatures.length === 0) { - // We found no signatures at all, which is an error - error(node.tagName, Diagnostics.JSX_element_type_0_does_not_have_any_construct_or_call_signatures, getTextOfNode(node.tagName)); return unknownType; }