@@ -11943,18 +11943,12 @@ namespace ts {
11943
11943
// Function interface, since they have none by default. This is a bit of a leap of faith
11944
11944
// that the user will not add any.
11945
11945
const callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call);
11946
-
11947
11946
const constructSignatures = getSignaturesOfType(apparentType, SignatureKind.Construct);
11948
- // TS 1.0 spec: 4.12
11949
- // If FuncExpr is of type Any, or of an object type that has no call or construct signatures
11950
- // but is a subtype of the Function interface, the call is an untyped function call. In an
11951
- // untyped function call no TypeArgs are permitted, Args can be any argument list, no contextual
11947
+
11948
+ // TS 1.0 Spec: 4.12
11949
+ // In an untyped function call no TypeArgs are permitted, Args can be any argument list, no contextual
11952
11950
// types are provided for the argument expressions, and the result is always of type Any.
11953
- // We exclude union types because we may have a union of function types that happen to have
11954
- // no common signatures.
11955
- if (isTypeAny(funcType) ||
11956
- (isTypeAny(apparentType) && funcType.flags & TypeFlags.TypeParameter) ||
11957
- (!callSignatures.length && !constructSignatures.length && !(funcType.flags & TypeFlags.Union) && isTypeAssignableTo(funcType, globalFunctionType))) {
11951
+ if (isUntypedFunctionCall(funcType, apparentType, callSignatures.length, constructSignatures.length)) {
11958
11952
// The unknownType indicates that an error already occurred (and was reported). No
11959
11953
// need to report another error in this case.
11960
11954
if (funcType !== unknownType && node.typeArguments) {
@@ -11977,6 +11971,29 @@ namespace ts {
11977
11971
return resolveCall(node, callSignatures, candidatesOutArray);
11978
11972
}
11979
11973
11974
+ /**
11975
+ * TS 1.0 spec: 4.12
11976
+ * If FuncExpr is of type Any, or of an object type that has no call or construct signatures
11977
+ * but is a subtype of the Function interface, the call is an untyped function call.
11978
+ */
11979
+ function isUntypedFunctionCall(funcType: Type, apparentFuncType: Type, numCallSignatures: number, numConstructSignatures: number) {
11980
+ if (isTypeAny(funcType)) {
11981
+ return true;
11982
+ }
11983
+ if (isTypeAny(apparentFuncType) && funcType.flags & TypeFlags.TypeParameter) {
11984
+ return true;
11985
+ }
11986
+ if (!numCallSignatures && !numConstructSignatures) {
11987
+ // We exclude union types because we may have a union of function types that happen to have
11988
+ // no common signatures.
11989
+ if (funcType.flags & TypeFlags.Union) {
11990
+ return false;
11991
+ }
11992
+ return isTypeAssignableTo(funcType, globalFunctionType);
11993
+ }
11994
+ return false;
11995
+ }
11996
+
11980
11997
function resolveNewExpression(node: NewExpression, candidatesOutArray: Signature[]): Signature {
11981
11998
if (node.arguments && languageVersion < ScriptTarget.ES5) {
11982
11999
const spreadIndex = getSpreadArgumentIndex(node.arguments);
@@ -12102,8 +12119,9 @@ namespace ts {
12102
12119
}
12103
12120
12104
12121
const callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call);
12122
+ const constructSignatures = getSignaturesOfType(apparentType, SignatureKind.Construct);
12105
12123
12106
- if (isTypeAny (tagType) || (! callSignatures.length && !(tagType.flags & TypeFlags.Union) && isTypeAssignableTo(tagType, globalFunctionType) )) {
12124
+ if (isUntypedFunctionCall (tagType, apparentType, callSignatures.length, constructSignatures.length )) {
12107
12125
return resolveUntypedCall(node);
12108
12126
}
12109
12127
@@ -12148,7 +12166,8 @@ namespace ts {
12148
12166
}
12149
12167
12150
12168
const callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call);
12151
- if (funcType === anyType || (!callSignatures.length && !(funcType.flags & TypeFlags.Union) && isTypeAssignableTo(funcType, globalFunctionType))) {
12169
+ const constructSignatures = getSignaturesOfType(apparentType, SignatureKind.Construct);
12170
+ if (isUntypedFunctionCall(funcType, apparentType, callSignatures.length, constructSignatures.length)) {
12152
12171
return resolveUntypedCall(node);
12153
12172
}
12154
12173
0 commit comments