diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts index aa4e03c05fb..361141a7d8a 100644 --- a/src/services/codefixes/helpers.ts +++ b/src/services/codefixes/helpers.ts @@ -397,7 +397,7 @@ export function createSignatureDeclarationFromSignature( let typeParameters = isJs ? undefined : signatureDeclaration.typeParameters; let parameters = signatureDeclaration.parameters; - let type = isJs ? undefined : signatureDeclaration.type; + let type = isJs ? undefined : getSynthesizedDeepClone(signatureDeclaration.type); if (importAdder) { if (typeParameters) { const newTypeParameters = sameMap(typeParameters, typeParameterDecl => { diff --git a/tests/cases/fourslash/codeFixClassImplementInterfaceTypeLiterals.ts b/tests/cases/fourslash/codeFixClassImplementInterfaceTypeLiterals.ts new file mode 100644 index 00000000000..68cdf5e7700 --- /dev/null +++ b/tests/cases/fourslash/codeFixClassImplementInterfaceTypeLiterals.ts @@ -0,0 +1,27 @@ +/// + +////type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; +//// +////export type DeepPartial = T extends Builtin ? T : +//// T extends Array ? Array> : +//// T extends ReadonlyArray ? ReadonlyArray> : +//// T extends {} ? { [K in keyof T]?: DeepPartial } : Partial; +//// +////export interface Nested { +//// field: string; +////} +//// +////interface Foo { +//// request(): DeepPartial<{ nested1: Nested; test2: Nested }>; +////} +////[|export class C implements Foo {}|] + +verify.codeFix({ + description: "Implement interface 'Foo'", + newRangeContent: +`export class C implements Foo { + request(): { nested1?: { field?: string; }; test2?: { field?: string; }; } { + throw new Error("Method not implemented."); + } +}`, +});