Skip to content

Commit 4fe59dc

Browse files
committed
Only defer pure functions and pure constructor functions during inference
1 parent fcd6f52 commit 4fe59dc

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8563,9 +8563,7 @@ namespace ts {
85638563
function getSignatureInstantiation(signature: Signature, typeArguments: Type[] | undefined, isJavascript: boolean, inferredTypeParameters?: ReadonlyArray<TypeParameter>): Signature {
85648564
const instantiatedSignature = getSignatureInstantiationWithoutFillingInTypeArguments(signature, fillMissingTypeArguments(typeArguments, signature.typeParameters, getMinTypeArgumentCount(signature.typeParameters), isJavascript));
85658565
if (inferredTypeParameters) {
8566-
const returnType = getReturnTypeOfSignature(instantiatedSignature);
8567-
const returnSignature = getSingleSignature(returnType, SignatureKind.Call, /*allowMembers*/ false) ||
8568-
getSingleSignature(returnType, SignatureKind.Construct, /*allowMembers*/ false);
8566+
const returnSignature = getSingleCallOrConstructSignature(getReturnTypeOfSignature(instantiatedSignature));
85698567
if (returnSignature) {
85708568
const newReturnSignature = cloneSignature(returnSignature);
85718569
newReturnSignature.typeParameters = inferredTypeParameters;
@@ -20427,6 +20425,11 @@ namespace ts {
2042720425
return getSingleSignature(type, SignatureKind.Call, /*allowMembers*/ false);
2042820426
}
2042920427

20428+
function getSingleCallOrConstructSignature(type: Type): Signature | undefined {
20429+
return getSingleSignature(type, SignatureKind.Call, /*allowMembers*/ false) ||
20430+
getSingleSignature(type, SignatureKind.Construct, /*allowMembers*/ false);
20431+
}
20432+
2043020433
function getSingleSignature(type: Type, kind: SignatureKind, allowMembers: boolean): Signature | undefined {
2043120434
if (type.flags & TypeFlags.Object) {
2043220435
const resolved = resolveStructuredTypeMembers(<ObjectType>type);
@@ -23775,7 +23778,7 @@ namespace ts {
2377523778
const constructSignature = getSingleSignature(type, SignatureKind.Construct, /*allowMembers*/ true);
2377623779
const signature = callSignature || constructSignature;
2377723780
if (signature && signature.typeParameters) {
23778-
if (checkMode & CheckMode.SkipGenericFunctions) {
23781+
if (checkMode & CheckMode.SkipGenericFunctions && getSingleCallOrConstructSignature(type)) {
2377923782
skippedGenericFunction(node, checkMode);
2378023783
return anyFunctionType;
2378123784
}
@@ -23791,9 +23794,7 @@ namespace ts {
2379123794
// if some of the outer function type parameters have no inferences so far. If so, we can
2379223795
// potentially add inferred type parameters to the outer function return type.
2379323796
const returnType = context.signature && getReturnTypeOfSignature(context.signature);
23794-
const returnSignature = returnType && (
23795-
getSingleSignature(returnType, SignatureKind.Call, /*allowMembers*/ false) ||
23796-
getSingleSignature(returnType, SignatureKind.Construct, /*allowMembers*/ false));
23797+
const returnSignature = returnType && getSingleCallOrConstructSignature(returnType);
2379723798
if (returnSignature && !returnSignature.typeParameters && !every(context.inferences, hasInferenceCandidates)) {
2379823799
// Instantiate the signature with its own type parameters as type arguments, possibly
2379923800
// renaming the type parameters to ensure they have unique names.

0 commit comments

Comments
 (0)