mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-14 16:56:06 -05:00
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:
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user