fix(47954): Auto implementation of interface with a constructor prop causes error (#50709)

* fix(47954): convert constructor property to computed name

* handle more nodes with constructor name
This commit is contained in:
Oleksandr T
2022-12-13 01:28:03 +02:00
committed by GitHub
parent 8f2a38f44b
commit 790c03d7b0
3 changed files with 39 additions and 0 deletions

View File

@@ -305,6 +305,9 @@ export function addNewNodeForMemberSymbol(
}
function createName(node: PropertyName) {
if (isIdentifier(node) && node.escapedText === "constructor") {
return factory.createComputedPropertyName(factory.createStringLiteral(idText(node), quotePreference === QuotePreference.Single));
}
return getSynthesizedDeepClone(node, /*includeTrivia*/ false);
}

View File

@@ -0,0 +1,17 @@
/// <reference path='fourslash.ts' />
////interface I {
//// constructor: number;
////}
////class C implements I {}
verify.codeFix({
description: "Implement interface 'I'",
newFileContent:
`interface I {
constructor: number;
}
class C implements I {
["constructor"]: number;
}`,
});

View File

@@ -0,0 +1,19 @@
/// <reference path='fourslash.ts' />
////interface I {
//// constructor(): number;
////}
////class C implements I {}
verify.codeFix({
description: "Implement interface 'I'",
newFileContent:
`interface I {
constructor(): number;
}
class C implements I {
["constructor"](): number {
throw new Error("Method not implemented.");
}
}`,
});