Skip to content

Commit d25bcea

Browse files
committed
Don't bother doing inference from the function parameter if you are about to fix the type parameter
1 parent 263c54e commit d25bcea

File tree

2 files changed

+6
-24
lines changed

2 files changed

+6
-24
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4239,17 +4239,6 @@ namespace ts {
42394239
return mapper;
42404240
}
42414241

4242-
function fixTypeParametersAfterInferringFromContextualParameterTypes(context: InferenceContext): void {
4243-
for (let i = 0; i < context.typeParameters.length; i++) {
4244-
let typeParameterInfo = context.inferences[i];
4245-
if (typeParameterInfo.fixAfterInferringFromContextualParameterType) {
4246-
typeParameterInfo.fixAfterInferringFromContextualParameterType = false;
4247-
typeParameterInfo.isFixed = true;
4248-
getInferredType(context, i);
4249-
}
4250-
}
4251-
}
4252-
42534242
function identityMapper(type: Type): Type {
42544243
return type;
42554244
}
@@ -5412,8 +5401,7 @@ namespace ts {
54125401
let inferences: TypeInferences[] = [];
54135402
for (let unused of typeParameters) {
54145403
inferences.push({
5415-
primary: undefined, secondary: undefined,
5416-
isFixed: false, fixAfterInferringFromContextualParameterType: false
5404+
primary: undefined, secondary: undefined, isFixed: false
54175405
});
54185406
}
54195407
return {
@@ -5424,7 +5412,7 @@ namespace ts {
54245412
};
54255413
}
54265414

5427-
function inferTypes(context: InferenceContext, source: Type, target: Type, inferringFromContextuallyTypedParameter: boolean) {
5415+
function inferTypes(context: InferenceContext, source: Type, target: Type) {
54285416
let sourceStack: Type[];
54295417
let targetStack: Type[];
54305418
let depth = 0;
@@ -5463,9 +5451,6 @@ namespace ts {
54635451
if (!contains(candidates, source)) {
54645452
candidates.push(source);
54655453
}
5466-
if (inferringFromContextuallyTypedParameter) {
5467-
inferences.fixAfterInferringFromContextualParameterType = true;
5468-
}
54695454
}
54705455
return;
54715456
}
@@ -7854,7 +7839,7 @@ namespace ts {
78547839
let context = createInferenceContext(signature.typeParameters, /*inferUnionTypes*/ true);
78557840
forEachMatchingParameterType(contextualSignature, signature, (source, target) => {
78567841
// Type parameters from outer context referenced by source type are fixed by instantiation of the source type
7857-
inferTypes(context, instantiateType(source, contextualMapper), target, false);
7842+
inferTypes(context, instantiateType(source, contextualMapper), target);
78587843
});
78597844
return getSignatureInstantiation(signature, getInferredTypes(context));
78607845
}
@@ -7904,7 +7889,7 @@ namespace ts {
79047889
argType = checkExpressionWithContextualType(arg, paramType, mapper);
79057890
}
79067891

7907-
inferTypes(context, argType, paramType, false);
7892+
inferTypes(context, argType, paramType);
79087893
}
79097894
}
79107895

@@ -7919,7 +7904,7 @@ namespace ts {
79197904
if (excludeArgument[i] === false) {
79207905
let arg = args[i];
79217906
let paramType = getTypeAtPosition(signature, i);
7922-
inferTypes(context, checkExpressionWithContextualType(arg, paramType, inferenceMapper), paramType, false);
7907+
inferTypes(context, checkExpressionWithContextualType(arg, paramType, inferenceMapper), paramType);
79237908
}
79247909
}
79257910
}
@@ -8823,8 +8808,7 @@ namespace ts {
88238808
parameterLinks.type = instantiateType(contextualType, mapper);
88248809
}
88258810
else if (isInferentialContext(mapper)) {
8826-
inferTypes(mapper.context, parameterLinks.type, contextualType, true);
8827-
fixTypeParametersAfterInferringFromContextualParameterTypes(mapper.context);
8811+
inferTypes(mapper.context, parameterLinks.type, instantiateType(contextualType, mapper));
88288812
}
88298813
}
88308814

src/compiler/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,8 +1902,6 @@ namespace ts {
19021902
secondary: Type[]; // Inferences made to a type parameter in a union type
19031903
isFixed: boolean; // Whether the type parameter is fixed, as defined in section 4.12.2 of the TypeScript spec
19041904
// If a type parameter is fixed, no more inferences can be made for the type parameter
1905-
1906-
fixAfterInferringFromContextualParameterType: boolean;
19071905
}
19081906

19091907
/* @internal */

0 commit comments

Comments
 (0)