Skip to content

Commit

Permalink
fix(59558): Implement Interface Quick Fix generates duplicate declara…
Browse files Browse the repository at this point in the history
…tions (#59563)
  • Loading branch information
a-tarasyuk authored Aug 16, 2024
1 parent 8ec3804 commit f850298
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/services/codefixes/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ export function addNewNodeForMemberSymbol(
}

for (const signature of signatures) {
if (signature.declaration && (signature.declaration.flags & NodeFlags.Ambient)) {
continue;
}
// Ensure nodes are fresh so they can have different positions when going through formatting.
outputMethod(quotePreference, signature, modifiers, createName(declarationName));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/// <reference path='fourslash.ts' />

// @lib: esnext
// @target: esnext

// @Filename: /node_modules/@types/node/globals.d.ts
////export {};
////declare global {
//// interface SymbolConstructor {
//// readonly dispose: unique symbol;
//// }
//// interface Disposable {
//// [Symbol.dispose](): void;
//// }
////}

// @Filename: /node_modules/@types/node/index.d.ts
/////// <reference path="globals.d.ts" />

// @Filename: a.ts
////class Foo implements Disposable {}

goTo.file("a.ts");
verify.codeFix({
description: "Implement interface 'Disposable'",
newFileContent:
`class Foo implements Disposable {
[Symbol.dispose](): void {
throw new Error("Method not implemented.");
}
}`
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// <reference path='fourslash.ts' />

////declare class A {
//// method(): void;
////}
////class B implements A {}

verify.codeFix({
description: "Implement interface 'A'",
newFileContent:
`declare class A {
method(): void;
}
class B implements A {
method(): void {
throw new Error("Method not implemented.");
}
}`
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// <reference path='fourslash.ts' />

////declare abstract class A {
//// abstract method(): void;
////}
////class B implements A {}

verify.codeFix({
description: "Implement interface 'A'",
newFileContent:
`declare abstract class A {
abstract method(): void;
}
class B implements A {
method(): void {
throw new Error("Method not implemented.");
}
}`
});

0 comments on commit f850298

Please sign in to comment.