@@ -15892,7 +15892,7 @@ namespace ts {
1589215892 const callSignatures = getSignaturesOfType(expressionType, SignatureKind.Call);
1589315893 if (callSignatures.length) {
1589415894 const signature = resolveCall(node, callSignatures, candidatesOutArray);
15895- if (!isInJavaScriptFile (signature.declaration) && getReturnTypeOfSignature(signature) !== voidType) {
15895+ if (!isJavaScriptConstructor (signature.declaration) && getReturnTypeOfSignature(signature) !== voidType) {
1589615896 error(node, Diagnostics.Only_a_void_function_can_be_called_with_the_new_keyword);
1589715897 }
1589815898 if (getThisTypeOfSignature(signature) === voidType) {
@@ -16119,6 +16119,26 @@ namespace ts {
1611916119 return getNodeLinks(node).resolvedSignature === resolvingSignature ? resolvingSignature : getResolvedSignature(node);
1612016120 }
1612116121
16122+ /**
16123+ * Indicates whether a declaration can be treated as a constructor in a JavaScript
16124+ * file.
16125+ */
16126+ function isJavaScriptConstructor(node: Declaration): boolean {
16127+ if (isInJavaScriptFile(node)) {
16128+ // If the node has a @class tag, treat it like a constructor.
16129+ if (getJSDocClassTag(node)) return true;
16130+
16131+ // If the symbol of the node has members, treat it like a constructor.
16132+ const symbol = isFunctionDeclaration(node) || isFunctionExpression(node) ? getSymbolOfNode(node) :
16133+ isVariableDeclaration(node) && isFunctionExpression(node.initializer) ? getSymbolOfNode(node.initializer) :
16134+ undefined;
16135+
16136+ return symbol && symbol.members !== undefined;
16137+ }
16138+
16139+ return false;
16140+ }
16141+
1612216142 function getInferredClassType(symbol: Symbol) {
1612316143 const links = getSymbolLinks(symbol);
1612416144 if (!links.inferredClassType) {
0 commit comments