Skip to content

Commit f850298

Browse files
authored
fix(59558): Implement Interface Quick Fix generates duplicate declarations (#59563)
1 parent 8ec3804 commit f850298

4 files changed

+73
-0
lines changed

src/services/codefixes/helpers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ export function addNewNodeForMemberSymbol(
301301
}
302302

303303
for (const signature of signatures) {
304+
if (signature.declaration && (signature.declaration.flags & NodeFlags.Ambient)) {
305+
continue;
306+
}
304307
// Ensure nodes are fresh so they can have different positions when going through formatting.
305308
outputMethod(quotePreference, signature, modifiers, createName(declarationName));
306309
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @lib: esnext
4+
// @target: esnext
5+
6+
// @Filename: /node_modules/@types/node/globals.d.ts
7+
////export {};
8+
////declare global {
9+
//// interface SymbolConstructor {
10+
//// readonly dispose: unique symbol;
11+
//// }
12+
//// interface Disposable {
13+
//// [Symbol.dispose](): void;
14+
//// }
15+
////}
16+
17+
// @Filename: /node_modules/@types/node/index.d.ts
18+
/////// <reference path="globals.d.ts" />
19+
20+
// @Filename: a.ts
21+
////class Foo implements Disposable {}
22+
23+
goTo.file("a.ts");
24+
verify.codeFix({
25+
description: "Implement interface 'Disposable'",
26+
newFileContent:
27+
`class Foo implements Disposable {
28+
[Symbol.dispose](): void {
29+
throw new Error("Method not implemented.");
30+
}
31+
}`
32+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////declare class A {
4+
//// method(): void;
5+
////}
6+
////class B implements A {}
7+
8+
verify.codeFix({
9+
description: "Implement interface 'A'",
10+
newFileContent:
11+
`declare class A {
12+
method(): void;
13+
}
14+
class B implements A {
15+
method(): void {
16+
throw new Error("Method not implemented.");
17+
}
18+
}`
19+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////declare abstract class A {
4+
//// abstract method(): void;
5+
////}
6+
////class B implements A {}
7+
8+
verify.codeFix({
9+
description: "Implement interface 'A'",
10+
newFileContent:
11+
`declare abstract class A {
12+
abstract method(): void;
13+
}
14+
class B implements A {
15+
method(): void {
16+
throw new Error("Method not implemented.");
17+
}
18+
}`
19+
});

0 commit comments

Comments
 (0)