@@ -9177,13 +9177,14 @@ namespace ts {
9177
9177
}
9178
9178
}
9179
9179
9180
- function createInferenceContext(signature: Signature, inferUnionTypes: boolean): InferenceContext {
9180
+ function createInferenceContext(signature: Signature, inferUnionTypes: boolean, useAnyForNoInferences: boolean ): InferenceContext {
9181
9181
const inferences = map(signature.typeParameters, createTypeInferencesObject);
9182
9182
return {
9183
9183
signature,
9184
9184
inferUnionTypes,
9185
9185
inferences,
9186
9186
inferredTypes: new Array(signature.typeParameters.length),
9187
+ useAnyForNoInferences
9187
9188
};
9188
9189
}
9189
9190
@@ -9613,6 +9614,9 @@ namespace ts {
9613
9614
context.inferredTypes[index] = inferredType = instantiatedConstraint;
9614
9615
}
9615
9616
}
9617
+ if (context.useAnyForNoInferences && !inferences.length && inferredType === emptyObjectType) {
9618
+ context.inferredTypes[index] = inferredType = anyType;
9619
+ }
9616
9620
}
9617
9621
else if (context.failedTypeParameterIndex === undefined || context.failedTypeParameterIndex > index) {
9618
9622
// 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 {
13634
13638
13635
13639
// Instantiate a generic signature in the context of a non-generic signature (section 3.8.5 in TypeScript spec)
13636
13640
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 );
13638
13642
forEachMatchingParameterType(contextualSignature, signature, (source, target) => {
13639
13643
// Type parameters from outer context referenced by source type are fixed by instantiation of the source type
13640
13644
inferTypesWithContext(context, instantiateType(source, contextualMapper), target);
@@ -14335,7 +14339,7 @@ namespace ts {
14335
14339
let candidate: Signature;
14336
14340
let typeArgumentsAreValid: boolean;
14337
14341
const inferenceContext = originalCandidate.typeParameters
14338
- ? createInferenceContext(originalCandidate, /*inferUnionTypes*/ false)
14342
+ ? createInferenceContext(originalCandidate, /*inferUnionTypes*/ false, /*useAnyForNoInferences*/ isInJavaScriptFile(node) )
14339
14343
: undefined;
14340
14344
14341
14345
while (true) {
0 commit comments