Expand constraint suggestion related span and add quick fix (#49481)

* Expand constraint suggestion related span and add quick fix

* Remove circular constraint suggestions

* Add error code

* Style feedback and new error code in quickfix
This commit is contained in:
Wesley Wigham
2022-06-15 10:35:51 -07:00
committed by GitHub
parent eb4b8a4d2e
commit ba38fe1df2
80 changed files with 336 additions and 13 deletions

View File

@@ -18806,8 +18806,13 @@ namespace ts {
return;
}
reportRelationError(headMessage, source, target);
if (strictNullChecks && source.flags & TypeFlags.TypeVariable && source.symbol?.declarations?.[0] && !getConstraintOfType(source as TypeVariable) && isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~TypeFlags.NonPrimitive))) {
associateRelatedInfo(createDiagnosticForNode(source.symbol.declarations[0], Diagnostics.This_type_parameter_probably_needs_an_extends_object_constraint));
if (source.flags & TypeFlags.TypeParameter && source.symbol?.declarations?.[0] && !getConstraintOfType(source as TypeVariable)) {
const syntheticParam = cloneTypeParameter(source as TypeParameter);
syntheticParam.constraint = instantiateType(target, makeUnaryTypeMapper(source, syntheticParam));
if (hasNonCircularBaseConstraint(syntheticParam)) {
const targetConstraintString = typeToString(target, source.symbol.declarations[0]);
associateRelatedInfo(createDiagnosticForNode(source.symbol.declarations[0], Diagnostics.This_type_parameter_might_need_an_extends_0_constraint, targetConstraintString));
}
}
}

View File

@@ -1530,7 +1530,7 @@
"category": "Error",
"code": 2207
},
"This type parameter probably needs an `extends object` constraint.": {
"This type parameter might need an `extends {0}` constraint.": {
"category": "Error",
"code": 2208
},
@@ -1543,6 +1543,14 @@
"category": "Error",
"code": 2210
},
"Add `extends` constraint.": {
"category": "Message",
"code": 2211
},
"Add `extends` constraint to all type parameters": {
"category": "Message",
"code": 2212
},
"Duplicate identifier '{0}'.": {
"category": "Error",