Merge pull request #29647 from Microsoft/noConstraintsDuringInference

Only check constraints in final phase of type inference
This commit is contained in:
Anders Hejlsberg
2019-02-01 10:54:08 -08:00
committed by GitHub
7 changed files with 218 additions and 2 deletions

View File

@@ -14113,7 +14113,9 @@ namespace ts {
function mapper(t: Type): Type {
for (let i = 0; i < inferences.length; i++) {
if (t === inferences[i].typeParameter) {
inferences[i].isFixed = true;
if (!(context.flags & InferenceFlags.NoFixing)) {
inferences[i].isFixed = true;
}
return getInferredType(context, i);
}
}
@@ -14839,10 +14841,12 @@ namespace ts {
const constraint = getConstraintOfTypeParameter(inference.typeParameter);
if (constraint) {
context.flags |= InferenceFlags.NoFixing;
const instantiatedConstraint = instantiateType(constraint, context);
if (!context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) {
inference.inferredType = inferredType = instantiatedConstraint;
}
context.flags &= ~InferenceFlags.NoFixing;
}
}

View File

@@ -4341,6 +4341,7 @@ namespace ts {
None = 0, // No special inference behaviors
NoDefault = 1 << 0, // Infer unknownType for no inferences (otherwise anyType or emptyObjectType)
AnyDefault = 1 << 1, // Infer anyType for no inferences (otherwise emptyObjectType)
NoFixing = 1 << 2, // Disable type parameter fixing
}
/**