mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 04:43:37 -05:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}`,
|
||||
});
|
||||
@@ -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.");
|
||||
}
|
||||
}`,
|
||||
});
|
||||
Reference in New Issue
Block a user