@@ -14788,7 +14788,7 @@ namespace ts {
14788
14788
return getWidenedType(unwidenedType);
14789
14789
}
14790
14790
14791
- function getInferredType(context: InferenceContext, index: number): Type {
14791
+ function getInferredType(context: InferenceContext, index: number, ignoreConstraints = false ): Type {
14792
14792
const inference = context.inferences[index];
14793
14793
let inferredType = inference.inferredType;
14794
14794
if (!inferredType) {
@@ -14836,11 +14836,13 @@ namespace ts {
14836
14836
14837
14837
inference.inferredType = inferredType;
14838
14838
14839
- const constraint = getConstraintOfTypeParameter(inference.typeParameter);
14840
- if (constraint) {
14841
- const instantiatedConstraint = instantiateType(constraint, context);
14842
- if (!context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) {
14843
- inference.inferredType = inferredType = instantiatedConstraint;
14839
+ if (!ignoreConstraints) {
14840
+ const constraint = getConstraintOfTypeParameter(inference.typeParameter);
14841
+ if (constraint) {
14842
+ const instantiatedConstraint = instantiateType(constraint, context);
14843
+ if (!context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) {
14844
+ inference.inferredType = inferredType = instantiatedConstraint;
14845
+ }
14844
14846
}
14845
14847
}
14846
14848
}
@@ -14852,10 +14854,10 @@ namespace ts {
14852
14854
return isInJavaScriptFile ? anyType : emptyObjectType;
14853
14855
}
14854
14856
14855
- function getInferredTypes(context: InferenceContext): Type[] {
14857
+ function getInferredTypes(context: InferenceContext, ignoreConstraints = false ): Type[] {
14856
14858
const result: Type[] = [];
14857
14859
for (let i = 0; i < context.inferences.length; i++) {
14858
- result.push(getInferredType(context, i));
14860
+ result.push(getInferredType(context, i, ignoreConstraints ));
14859
14861
}
14860
14862
return result;
14861
14863
}
@@ -19925,7 +19927,10 @@ namespace ts {
19925
19927
inferTypes(context.inferences, spreadType, restType);
19926
19928
}
19927
19929
19928
- return getInferredTypes(context);
19930
+ // If we are excluding context sensitive arguments we know there is another round of type inference
19931
+ // coming, so we omit constraint checking. Otherwise, when a type parameter's constraint is self-
19932
+ // referential, checking the constraint would cause inferences to be fixed prematurely.
19933
+ return getInferredTypes(context, !!excludeArgument);
19929
19934
}
19930
19935
19931
19936
function getArrayifiedType(type: Type) {
0 commit comments