@@ -14470,7 +14470,7 @@ namespace ts {
14470
14470
const templateType = getTemplateTypeFromMappedType(target);
14471
14471
const inference = createInferenceInfo(typeParameter);
14472
14472
inferTypes([inference], sourceType, templateType);
14473
- return getTypeFromInference(inference);
14473
+ return getTypeFromInference(inference) || emptyObjectType ;
14474
14474
}
14475
14475
14476
14476
function* getUnmatchedProperties(source: Type, target: Type, requireOptionalProperties: boolean, matchDiscriminantProperties: boolean) {
@@ -14514,7 +14514,7 @@ namespace ts {
14514
14514
function getTypeFromInference(inference: InferenceInfo) {
14515
14515
return inference.candidates ? getUnionType(inference.candidates, UnionReduction.Subtype) :
14516
14516
inference.contraCandidates ? getIntersectionType(inference.contraCandidates) :
14517
- emptyObjectType ;
14517
+ undefined ;
14518
14518
}
14519
14519
14520
14520
function inferTypes(inferences: InferenceInfo[], originalSource: Type, originalTarget: Type, priority: InferencePriority = 0, contravariant = false) {
@@ -15016,8 +15016,8 @@ namespace ts {
15016
15016
15017
15017
function getInferredType(context: InferenceContext, index: number): Type {
15018
15018
const inference = context.inferences[index];
15019
- let inferredType = inference.inferredType;
15020
- if (! inferredType) {
15019
+ if (! inference.inferredType) {
15020
+ let inferredType: Type | undefined;
15021
15021
const signature = context.signature;
15022
15022
if (signature) {
15023
15023
const inferredCovariantType = inference.candidates ? getCovariantInference(inference, signature) : undefined;
@@ -15048,27 +15048,24 @@ namespace ts {
15048
15048
// parameter should be instantiated to the empty object type.
15049
15049
inferredType = instantiateType(defaultType, combineTypeMappers(createBackreferenceMapper(context, index), context.nonFixingMapper));
15050
15050
}
15051
- else {
15052
- inferredType = getDefaultTypeArgumentType(!!(context.flags & InferenceFlags.AnyDefault));
15053
- }
15054
15051
}
15055
15052
}
15056
15053
else {
15057
15054
inferredType = getTypeFromInference(inference);
15058
15055
}
15059
15056
15060
- inference.inferredType = inferredType;
15057
+ inference.inferredType = inferredType || getDefaultTypeArgumentType(!!(context.flags & InferenceFlags.AnyDefault)) ;
15061
15058
15062
15059
const constraint = getConstraintOfTypeParameter(inference.typeParameter);
15063
15060
if (constraint) {
15064
15061
const instantiatedConstraint = instantiateType(constraint, context.nonFixingMapper);
15065
- if (!context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) {
15062
+ if (!inferredType || ! context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) {
15066
15063
inference.inferredType = inferredType = instantiatedConstraint;
15067
15064
}
15068
15065
}
15069
15066
}
15070
15067
15071
- return inferredType;
15068
+ return inference. inferredType;
15072
15069
}
15073
15070
15074
15071
function getDefaultTypeArgumentType(isInJavaScriptFile: boolean): Type {
@@ -18046,8 +18043,13 @@ namespace ts {
18046
18043
function instantiateContextualType(contextualType: Type | undefined, node: Expression): Type | undefined {
18047
18044
if (contextualType && maybeTypeOfKind(contextualType, TypeFlags.Instantiable)) {
18048
18045
const inferenceContext = getInferenceContext(node);
18049
- if (inferenceContext && inferenceContext.returnMapper) {
18050
- return instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
18046
+ if (inferenceContext) {
18047
+ if ((isFunctionExpressionOrArrowFunction(node) || isObjectLiteralMethod(node)) && isContextSensitive(node)) {
18048
+ return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper);
18049
+ }
18050
+ if (inferenceContext.returnMapper) {
18051
+ return instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
18052
+ }
18051
18053
}
18052
18054
}
18053
18055
return contextualType;
0 commit comments