From 174e800fbb753c780e5d28e17f4006ad26762bfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Wed, 9 Apr 2025 21:38:11 +0200 Subject: [PATCH] Fix missing properties codefix for property assignment declarations --- src/services/codefixes/helpers.ts | 2 ++ ...ssImplementInterfacePropertyAssignment1.ts | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 tests/cases/fourslash/codeFixClassImplementInterfacePropertyAssignment1.ts diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts index ebb58bae13c09..c83f5482198a3 100644 --- a/src/services/codefixes/helpers.ts +++ b/src/services/codefixes/helpers.ts @@ -225,6 +225,8 @@ export function addNewNodeForMemberSymbol( switch (kind) { case SyntaxKind.PropertySignature: case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertyAssignment: + case SyntaxKind.ShorthandPropertyAssignment: let typeNode = checker.typeToTypeNode(type, enclosingDeclaration, flags, InternalNodeBuilderFlags.AllowUnresolvedNames, getNoopSymbolTrackerWithResolver(context)); if (importAdder) { const importableReference = tryGetAutoImportableReferenceFromTypeNode(typeNode, scriptTarget); diff --git a/tests/cases/fourslash/codeFixClassImplementInterfacePropertyAssignment1.ts b/tests/cases/fourslash/codeFixClassImplementInterfacePropertyAssignment1.ts new file mode 100644 index 0000000000000..286e77d99657a --- /dev/null +++ b/tests/cases/fourslash/codeFixClassImplementInterfacePropertyAssignment1.ts @@ -0,0 +1,30 @@ +/// + +//// const b = "foo"; +//// +//// const t = { +//// a: 1, +//// b, +//// }; +//// +//// type InferedT = typeof t; +//// +//// class InferedTClass implements InferedT {} + +verify.codeFix({ + description: "Implement interface 'InferedT'", + newFileContent: +`const b = "foo"; + +const t = { + a: 1, + b, +}; + +type InferedT = typeof t; + +class InferedTClass implements InferedT { + a: number; + b: string; +}`, +});