mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-10 06:41:59 -06:00
Issue errors for all circular type parameter constraints
This commit is contained in:
parent
fb0dcd4987
commit
ede6b9a5cb
@ -7577,7 +7577,19 @@ namespace ts {
|
||||
constraintDepth++;
|
||||
let result = computeBaseConstraint(getSimplifiedType(t));
|
||||
constraintDepth--;
|
||||
if (!popTypeResolution() || nonTerminating) {
|
||||
if (!popTypeResolution()) {
|
||||
if (t.flags & TypeFlags.TypeParameter) {
|
||||
const errorNode = getConstraintDeclaration(<TypeParameter>t);
|
||||
if (errorNode) {
|
||||
const diagnostic = error(errorNode, Diagnostics.Type_parameter_0_has_a_circular_constraint, typeToString(t));
|
||||
if (currentNode && !isNodeDescendantOf(errorNode, currentNode) && !isNodeDescendantOf(currentNode, errorNode)) {
|
||||
addRelatedInfo(diagnostic, createDiagnosticForNode(currentNode, Diagnostics.Circularity_originates_in_type_at_this_location));
|
||||
}
|
||||
}
|
||||
}
|
||||
result = circularConstraintType;
|
||||
}
|
||||
if (nonTerminating) {
|
||||
result = circularConstraintType;
|
||||
}
|
||||
t.immediateBaseConstraint = result || noConstraintType;
|
||||
@ -23475,9 +23487,8 @@ namespace ts {
|
||||
checkSourceElement(node.constraint);
|
||||
checkSourceElement(node.default);
|
||||
const typeParameter = getDeclaredTypeOfTypeParameter(getSymbolOfNode(node));
|
||||
if (!hasNonCircularBaseConstraint(typeParameter)) {
|
||||
error(getEffectiveConstraintOfTypeParameter(node), Diagnostics.Type_parameter_0_has_a_circular_constraint, typeToString(typeParameter));
|
||||
}
|
||||
// Resolve base constraint to reveal circularity errors
|
||||
getBaseConstraintOfType(typeParameter);
|
||||
if (!hasNonCircularTypeParameterDefault(typeParameter)) {
|
||||
error(node.default, Diagnostics.Type_parameter_0_has_a_circular_default, typeToString(typeParameter));
|
||||
}
|
||||
|
||||
@ -2589,6 +2589,10 @@
|
||||
"category": "Error",
|
||||
"code": 2750
|
||||
},
|
||||
"Circularity originates in type at this location.": {
|
||||
"category": "Error",
|
||||
"code": 2751
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user