diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 902353aded6..3c98513423a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -17234,7 +17234,7 @@ namespace ts { if (declaration && getModifierFlags(declaration) & ModifierFlags.Private) { const typeClassDeclaration = getClassLikeDeclarationOfSymbol(type.symbol); if (!isNodeWithinClass(node, typeClassDeclaration)) { - error(node, Diagnostics.Cannot_extend_a_class_0_Class_constructor_is_marked_as_private, (node.expression).text); + error(node, Diagnostics.Cannot_extend_a_class_0_Class_constructor_is_marked_as_private, getFullyQualifiedName(type.symbol)); } } } diff --git a/tests/baselines/reference/extendPrivateConstructorClass.errors.txt b/tests/baselines/reference/extendPrivateConstructorClass.errors.txt new file mode 100644 index 00000000000..02e9c6a1c88 --- /dev/null +++ b/tests/baselines/reference/extendPrivateConstructorClass.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/extendPrivateConstructorClass.ts(7,17): error TS2675: Cannot extend a class 'abc.XYZ'. Class constructor is marked as private. + + +==== tests/cases/compiler/extendPrivateConstructorClass.ts (1 errors) ==== + declare namespace abc { + class XYZ { + private constructor(); + } + } + + class C extends abc.XYZ { + ~~~~~~~ +!!! error TS2675: Cannot extend a class 'abc.XYZ'. Class constructor is marked as private. + } + \ No newline at end of file diff --git a/tests/baselines/reference/extendPrivateConstructorClass.js b/tests/baselines/reference/extendPrivateConstructorClass.js new file mode 100644 index 00000000000..8893e9735ff --- /dev/null +++ b/tests/baselines/reference/extendPrivateConstructorClass.js @@ -0,0 +1,24 @@ +//// [extendPrivateConstructorClass.ts] +declare namespace abc { + class XYZ { + private constructor(); + } +} + +class C extends abc.XYZ { +} + + +//// [extendPrivateConstructorClass.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var C = (function (_super) { + __extends(C, _super); + function C() { + return _super.apply(this, arguments) || this; + } + return C; +}(abc.XYZ)); diff --git a/tests/cases/compiler/extendPrivateConstructorClass.ts b/tests/cases/compiler/extendPrivateConstructorClass.ts new file mode 100644 index 00000000000..90629657f76 --- /dev/null +++ b/tests/cases/compiler/extendPrivateConstructorClass.ts @@ -0,0 +1,8 @@ +declare namespace abc { + class XYZ { + private constructor(); + } +} + +class C extends abc.XYZ { +}