@@ -9177,13 +9177,14 @@ namespace ts {
91779177 }
91789178 }
91799179
9180- function createInferenceContext(signature: Signature, inferUnionTypes: boolean): InferenceContext {
9180+ function createInferenceContext(signature: Signature, inferUnionTypes: boolean, useAnyForNoInferences: boolean ): InferenceContext {
91819181 const inferences = map(signature.typeParameters, createTypeInferencesObject);
91829182 return {
91839183 signature,
91849184 inferUnionTypes,
91859185 inferences,
91869186 inferredTypes: new Array(signature.typeParameters.length),
9187+ useAnyForNoInferences
91879188 };
91889189 }
91899190
@@ -9613,6 +9614,9 @@ namespace ts {
96139614 context.inferredTypes[index] = inferredType = instantiatedConstraint;
96149615 }
96159616 }
9617+ if (context.useAnyForNoInferences && !inferences.length && inferredType === emptyObjectType) {
9618+ context.inferredTypes[index] = inferredType = anyType;
9619+ }
96169620 }
96179621 else if (context.failedTypeParameterIndex === undefined || context.failedTypeParameterIndex > index) {
96189622 // If inference failed, it is necessary to record the index of the failed type parameter (the one we are on).
@@ -13634,7 +13638,7 @@ namespace ts {
1363413638
1363513639 // Instantiate a generic signature in the context of a non-generic signature (section 3.8.5 in TypeScript spec)
1363613640 function instantiateSignatureInContextOf(signature: Signature, contextualSignature: Signature, contextualMapper: TypeMapper): Signature {
13637- const context = createInferenceContext(signature, /*inferUnionTypes*/ true);
13641+ const context = createInferenceContext(signature, /*inferUnionTypes*/ true, /*useAnyForNoInferences*/ false );
1363813642 forEachMatchingParameterType(contextualSignature, signature, (source, target) => {
1363913643 // Type parameters from outer context referenced by source type are fixed by instantiation of the source type
1364013644 inferTypesWithContext(context, instantiateType(source, contextualMapper), target);
@@ -14335,7 +14339,7 @@ namespace ts {
1433514339 let candidate: Signature;
1433614340 let typeArgumentsAreValid: boolean;
1433714341 const inferenceContext = originalCandidate.typeParameters
14338- ? createInferenceContext(originalCandidate, /*inferUnionTypes*/ false)
14342+ ? createInferenceContext(originalCandidate, /*inferUnionTypes*/ false, /*useAnyForNoInferences*/ isInJavaScriptFile(node) )
1433914343 : undefined;
1434014344
1434114345 while (true) {
0 commit comments