Skip to content

Commit d70dc0a

Browse files
committed
Style feedback and new error code in quickfix
1 parent 9974a27 commit d70dc0a

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18793,9 +18793,9 @@ namespace ts {
1879318793
}
1879418794
reportRelationError(headMessage, source, target);
1879518795
if (source.flags & TypeFlags.TypeParameter && source.symbol?.declarations?.[0] && !getConstraintOfType(source as TypeVariable)) {
18796-
const syntheticparam = cloneTypeParameter(source as TypeParameter);
18797-
syntheticparam.constraint = instantiateType(target, makeUnaryTypeMapper(source, syntheticparam));
18798-
if (hasNonCircularBaseConstraint(syntheticparam)) {
18796+
const syntheticParam = cloneTypeParameter(source as TypeParameter);
18797+
syntheticParam.constraint = instantiateType(target, makeUnaryTypeMapper(source, syntheticParam));
18798+
if (hasNonCircularBaseConstraint(syntheticParam)) {
1879918799
const targetConstraintString = typeToString(target, source.symbol.declarations[0]);
1880018800
associateRelatedInfo(createDiagnosticForNode(source.symbol.declarations[0], Diagnostics.This_type_parameter_might_need_an_extends_0_constraint, targetConstraintString));
1880118801
}

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,10 @@
15471547
"category": "Message",
15481548
"code": 2211
15491549
},
1550+
"Add `extends` constraint to all type parameters": {
1551+
"category": "Message",
1552+
"code": 2212
1553+
},
15501554

15511555
"Duplicate identifier '{0}'.": {
15521556
"category": "Error",

src/services/codefixes/fixAddMissingConstraint.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace ts.codefix {
2222
return;
2323
}
2424
const changes = textChanges.ChangeTracker.with(context, t => addMissingConstraint(t, related));
25-
return [createCodeFixAction(fixId, changes, Diagnostics.Add_extends_constraint, fixId, Diagnostics.Add_missing_new_operator_to_all_calls)];
25+
return [createCodeFixAction(fixId, changes, Diagnostics.Add_extends_constraint, fixId, Diagnostics.Add_extends_constraint_to_all_type_parameters)];
2626
},
2727
fixIds: [fixId],
2828
getAllCodeActions: context => codeFixAll(context, errorCodes, (changes, diag) => {
@@ -33,11 +33,9 @@ namespace ts.codefix {
3333
});
3434

3535
function getDiagnosticRelatedInfo(program: Program, sourceFile: SourceFile, span: TextSpan) {
36-
const diags = program.getSemanticDiagnostics(sourceFile).filter(diag => diag.start === span.start && diag.length === span.length);
37-
if (!length(diags)) return;
38-
const diag = diags[0];
39-
if (!diag.relatedInformation) return;
40-
const related = filter(diag.relatedInformation, related => related.code === Diagnostics.This_type_parameter_might_need_an_extends_0_constraint.code)[0];
36+
const diag = find(program.getSemanticDiagnostics(sourceFile), diag => diag.start === span.start && diag.length === span.length);
37+
if (!diag || !diag.relatedInformation) return;
38+
const related = find(diag.relatedInformation, related => related.code === Diagnostics.This_type_parameter_might_need_an_extends_0_constraint.code);
4139
if (!related) return;
4240
return related;
4341
}

0 commit comments

Comments
 (0)