fix(59558): Implement Interface Quick Fix generates duplicate declarations (#59563)

This commit is contained in:
Oleksandr T.
2024-08-17 01:17:58 +03:00
committed by GitHub
parent 8ec3804611
commit f850298f70
4 changed files with 73 additions and 0 deletions

View File

@@ -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));
}

View File

@@ -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.");
}
}`
});

View File

@@ -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.");
}
}`
});

View File

@@ -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.");
}
}`
});