Skip to content

Commit 66c1178

Browse files
masaeedumhegazy
authored andcommitted
Use symbol fully-qualified name instead of node text in error message (#11761)
* Add test * Add baselines * Use fqn of symbol instead of node text
1 parent 48f947f commit 66c1178

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17234,7 +17234,7 @@ namespace ts {
1723417234
if (declaration && getModifierFlags(declaration) & ModifierFlags.Private) {
1723517235
const typeClassDeclaration = <ClassLikeDeclaration>getClassLikeDeclarationOfSymbol(type.symbol);
1723617236
if (!isNodeWithinClass(node, typeClassDeclaration)) {
17237-
error(node, Diagnostics.Cannot_extend_a_class_0_Class_constructor_is_marked_as_private, (<Identifier>node.expression).text);
17237+
error(node, Diagnostics.Cannot_extend_a_class_0_Class_constructor_is_marked_as_private, getFullyQualifiedName(type.symbol));
1723817238
}
1723917239
}
1724017240
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
tests/cases/compiler/extendPrivateConstructorClass.ts(7,17): error TS2675: Cannot extend a class 'abc.XYZ'. Class constructor is marked as private.
2+
3+
4+
==== tests/cases/compiler/extendPrivateConstructorClass.ts (1 errors) ====
5+
declare namespace abc {
6+
class XYZ {
7+
private constructor();
8+
}
9+
}
10+
11+
class C extends abc.XYZ {
12+
~~~~~~~
13+
!!! error TS2675: Cannot extend a class 'abc.XYZ'. Class constructor is marked as private.
14+
}
15+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//// [extendPrivateConstructorClass.ts]
2+
declare namespace abc {
3+
class XYZ {
4+
private constructor();
5+
}
6+
}
7+
8+
class C extends abc.XYZ {
9+
}
10+
11+
12+
//// [extendPrivateConstructorClass.js]
13+
var __extends = (this && this.__extends) || function (d, b) {
14+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
15+
function __() { this.constructor = d; }
16+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
17+
};
18+
var C = (function (_super) {
19+
__extends(C, _super);
20+
function C() {
21+
return _super.apply(this, arguments) || this;
22+
}
23+
return C;
24+
}(abc.XYZ));
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
declare namespace abc {
2+
class XYZ {
3+
private constructor();
4+
}
5+
}
6+
7+
class C extends abc.XYZ {
8+
}

0 commit comments

Comments
 (0)