Skip to content

Commit 5856cc5

Browse files
committed
Merge pull request #4501 from Microsoft/checkClassExpressions
Properly check expressions in class extends clause
2 parents c56683c + c0267ec commit 5856cc5

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12614,6 +12614,7 @@ namespace ts {
1261412614
if (baseTypes.length && produceDiagnostics) {
1261512615
let baseType = baseTypes[0];
1261612616
let staticBaseType = getBaseConstructorTypeOfClass(type);
12617+
checkSourceElement(baseTypeNode.expression);
1261712618
if (baseTypeNode.typeArguments) {
1261812619
forEach(baseTypeNode.typeArguments, checkSourceElement);
1261912620
for (let constructor of getConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments)) {
@@ -13683,6 +13684,8 @@ namespace ts {
1368313684
case SyntaxKind.VariableDeclaration:
1368413685
case SyntaxKind.VariableDeclarationList:
1368513686
case SyntaxKind.ClassDeclaration:
13687+
case SyntaxKind.HeritageClause:
13688+
case SyntaxKind.ExpressionWithTypeArguments:
1368613689
case SyntaxKind.EnumDeclaration:
1368713690
case SyntaxKind.EnumMember:
1368813691
case SyntaxKind.ExportAssignment:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
tests/cases/compiler/missingPropertiesOfClassExpression.ts(1,52): error TS2339: Property 'y' does not exist on type '(Anonymous class)'.
2+
3+
4+
==== tests/cases/compiler/missingPropertiesOfClassExpression.ts (1 errors) ====
5+
class George extends class { reset() { return this.y; } } {
6+
~
7+
!!! error TS2339: Property 'y' does not exist on type '(Anonymous class)'.
8+
constructor() {
9+
super();
10+
}
11+
}
12+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//// [missingPropertiesOfClassExpression.ts]
2+
class George extends class { reset() { return this.y; } } {
3+
constructor() {
4+
super();
5+
}
6+
}
7+
8+
9+
//// [missingPropertiesOfClassExpression.js]
10+
var __extends = (this && this.__extends) || function (d, b) {
11+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
12+
function __() { this.constructor = d; }
13+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14+
};
15+
var George = (function (_super) {
16+
__extends(George, _super);
17+
function George() {
18+
_super.call(this);
19+
}
20+
return George;
21+
})((function () {
22+
function class_1() {
23+
}
24+
class_1.prototype.reset = function () { return this.y; };
25+
return class_1;
26+
})());
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class George extends class { reset() { return this.y; } } {
2+
constructor() {
3+
super();
4+
}
5+
}

0 commit comments

Comments
 (0)