Only collect inferences which actually have inferences into the returnMapper (#30111)

This commit is contained in:
Wesley Wigham
2019-02-28 12:46:24 -08:00
committed by GitHub
parent 5ec5e0466d
commit a6a3ae00a6
5 changed files with 189 additions and 2 deletions

View File

@@ -10691,6 +10691,23 @@ namespace ts {
mapper;
}
function cloneInferredPartOfContext(context: InferenceContext): InferenceContext | undefined {
// Filter context to only those parameters which actually have inference candidates
const params = [];
const inferences = [];
for (let i = 0; i < context.typeParameters.length; i++) {
const info = context.inferences[i];
if (info.candidates || info.contraCandidates) {
params.push(context.typeParameters[i]);
inferences.push(info);
}
}
if (!params.length) {
return undefined;
}
return createInferenceContext(params, context.signature, context.flags | InferenceFlags.NoDefault, context.compareTypes, inferences);
}
function combineTypeMappers(mapper1: TypeMapper | undefined, mapper2: TypeMapper): TypeMapper;
function combineTypeMappers(mapper1: TypeMapper, mapper2: TypeMapper | undefined): TypeMapper;
function combineTypeMappers(mapper1: TypeMapper, mapper2: TypeMapper): TypeMapper {
@@ -14900,7 +14917,7 @@ namespace ts {
// parameter should be instantiated to the empty object type.
inferredType = instantiateType(defaultType,
combineTypeMappers(
createBackreferenceMapper(context.signature!.typeParameters!, index),
createBackreferenceMapper(context.typeParameters, index),
context));
}
else {
@@ -20069,7 +20086,7 @@ namespace ts {
inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, InferencePriority.ReturnType);
// Create a type mapper for instantiating generic contextual types using the inferences made
// from the return type.
context.returnMapper = cloneTypeMapper(context);
context.returnMapper = cloneInferredPartOfContext(context);
}
}