mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 11:24:29 -05:00
Only collect inferences which actually have inferences into the returnMapper (#30111)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user