mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
Merge pull request #29647 from Microsoft/noConstraintsDuringInference
Only check constraints in final phase of type inference
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user