For missing constraint quickfix insert position, Use node name end rather than related span end (#49673)

This commit is contained in:
Wesley Wigham
2022-06-29 11:46:42 -07:00
committed by GitHub
parent cba184f69b
commit 52f4055174
2 changed files with 18 additions and 1 deletions

View File

@@ -51,7 +51,7 @@ namespace ts.codefix {
if (!newConstraint) return;
const newConstraintText = newConstraint[1];
changes.insertText(related.file!, related.start! + related.length!, ` extends ${newConstraintText}`);
changes.insertText(related.file!, decl.name.end, ` extends ${newConstraintText}`);
}
function findAncestorMatchingSpan(sourceFile: SourceFile, span: TextSpan): Node {

View File

@@ -0,0 +1,17 @@
/// <reference path="fourslash.ts" />
// @Filename: file.ts
////function f<T = `${number}`>(x: T) {
//// const y: `${number}` = x/**/;
////}
goTo.marker("");
verify.codeFix({
index: 0,
description: "Add `extends` constraint.",
newFileContent: {
"/tests/cases/fourslash/file.ts":
`function f<T extends \`$\{number}\` = \`$\{number}\`>(x: T) {
const y: \`$\{number}\` = x;
}`
}
});