diff --git a/src/services/codefixes/fixAddMissingConstraint.ts b/src/services/codefixes/fixAddMissingConstraint.ts index 2520c806e6690..2d3b6c51a346c 100644 --- a/src/services/codefixes/fixAddMissingConstraint.ts +++ b/src/services/codefixes/fixAddMissingConstraint.ts @@ -26,14 +26,13 @@ namespace ts.codefix { fixIds: [fixId], getAllCodeActions: context => { const { program, preferences, host } = context; - const seen = new Map(); + const seen = new Map(); return createCombinedCodeActions(textChanges.ChangeTracker.with(context, changes => { eachDiagnostic(context, errorCodes, diag => { const info = getInfo(program, diag.file, createTextSpan(diag.start, diag.length)); if (info) { - const id = getNodeId(info.declaration) + "#" + info.token.getText(); - if (addToSeen(seen, id)) { + if (addToSeen(seen, getNodeId(info.declaration))) { return addMissingConstraint(changes, program, preferences, host, diag.file, info); } } diff --git a/tests/cases/fourslash/quickfixAddMissingConstraint5.ts b/tests/cases/fourslash/quickfixAddMissingConstraint5.ts new file mode 100644 index 0000000000000..8bf86e6418437 --- /dev/null +++ b/tests/cases/fourslash/quickfixAddMissingConstraint5.ts @@ -0,0 +1,39 @@ +/// + +// @strict: true +// @filename: /foo.ts +////export interface RendererElement { +//// [key: string]: any +////} +//// +////export interface VNode { +//// target: HostElement | null; +////} +//// +////export function cloneVNode(vnode: VNode): VNode { +//// const cloned: VNode = { +//// target: vnode.target, +//// } +//// return cloned; +////} + +goTo.file("/foo.ts"); +verify.codeFixAll({ + fixId: "addMissingConstraint", + fixAllDescription: ts.Diagnostics.Add_extends_constraint_to_all_type_parameters.message, + newFileContent: +`export interface RendererElement { + [key: string]: any +} + +export interface VNode { + target: HostElement | null; +} + +export function cloneVNode(vnode: VNode): VNode { + const cloned: VNode = { + target: vnode.target, + } + return cloned; +}` +})