Merge pull request #4501 from Microsoft/checkClassExpressions

Properly check expressions in class extends clause
This commit is contained in:
Anders Hejlsberg
2015-08-27 16:21:02 -07:00
4 changed files with 46 additions and 0 deletions

View File

@@ -12614,6 +12614,7 @@ namespace ts {
if (baseTypes.length && produceDiagnostics) {
let baseType = baseTypes[0];
let staticBaseType = getBaseConstructorTypeOfClass(type);
checkSourceElement(baseTypeNode.expression);
if (baseTypeNode.typeArguments) {
forEach(baseTypeNode.typeArguments, checkSourceElement);
for (let constructor of getConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments)) {
@@ -13683,6 +13684,8 @@ namespace ts {
case SyntaxKind.VariableDeclaration:
case SyntaxKind.VariableDeclarationList:
case SyntaxKind.ClassDeclaration:
case SyntaxKind.HeritageClause:
case SyntaxKind.ExpressionWithTypeArguments:
case SyntaxKind.EnumDeclaration:
case SyntaxKind.EnumMember:
case SyntaxKind.ExportAssignment:

View File

@@ -0,0 +1,12 @@
tests/cases/compiler/missingPropertiesOfClassExpression.ts(1,52): error TS2339: Property 'y' does not exist on type '(Anonymous class)'.
==== tests/cases/compiler/missingPropertiesOfClassExpression.ts (1 errors) ====
class George extends class { reset() { return this.y; } } {
~
!!! error TS2339: Property 'y' does not exist on type '(Anonymous class)'.
constructor() {
super();
}
}

View File

@@ -0,0 +1,26 @@
//// [missingPropertiesOfClassExpression.ts]
class George extends class { reset() { return this.y; } } {
constructor() {
super();
}
}
//// [missingPropertiesOfClassExpression.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 George = (function (_super) {
__extends(George, _super);
function George() {
_super.call(this);
}
return George;
})((function () {
function class_1() {
}
class_1.prototype.reset = function () { return this.y; };
return class_1;
})());

View File

@@ -0,0 +1,5 @@
class George extends class { reset() { return this.y; } } {
constructor() {
super();
}
}