Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12337,12 +12337,15 @@ namespace ts {
// - In a static member function or static member accessor
// where this references the constructor function object of a derived class,
// a super property access is permitted and must specify a public static member function of the base class.
if (languageVersion < ScriptTarget.ES2015 && getDeclarationKindFromSymbol(prop) !== SyntaxKind.MethodDeclaration) {
// `prop` refers to a *property* declared in the super class
// rather than a *method*, so it does not satisfy the above criteria.
if (languageVersion < ScriptTarget.ES2015) {
const propKind = getDeclarationKindFromSymbol(prop);
if (propKind !== SyntaxKind.MethodDeclaration && propKind !== SyntaxKind.MethodSignature) {
// `prop` refers to a *property* declared in the super class
// rather than a *method*, so it does not satisfy the above criteria.

error(errorNode, Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword);
return false;
error(errorNode, Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword);
return false;
}
}

if (flags & ModifierFlags.Abstract) {
Expand Down
37 changes: 37 additions & 0 deletions tests/baselines/reference/superHasMethodsFromMergedInterface.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//// [superHasMethodsFromMergedInterface.ts]
class C { m1() { } }
interface C { m2(): void }
class Sub extends C {
m3() {
super.m2();
}
}


//// [superHasMethodsFromMergedInterface.js]
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var C = (function () {
function C() {
}
C.prototype.m1 = function () { };
return C;
}());
var Sub = (function (_super) {
__extends(Sub, _super);
function Sub() {
return _super !== null && _super.apply(this, arguments) || this;
}
Sub.prototype.m3 = function () {
_super.prototype.m2.call(this);
};
return Sub;
}(C));
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
=== tests/cases/compiler/superHasMethodsFromMergedInterface.ts ===
class C { m1() { } }
>C : Symbol(C, Decl(superHasMethodsFromMergedInterface.ts, 0, 0), Decl(superHasMethodsFromMergedInterface.ts, 0, 20))
>m1 : Symbol(C.m1, Decl(superHasMethodsFromMergedInterface.ts, 0, 9))

interface C { m2(): void }
>C : Symbol(C, Decl(superHasMethodsFromMergedInterface.ts, 0, 0), Decl(superHasMethodsFromMergedInterface.ts, 0, 20))
>m2 : Symbol(C.m2, Decl(superHasMethodsFromMergedInterface.ts, 1, 13))

class Sub extends C {
>Sub : Symbol(Sub, Decl(superHasMethodsFromMergedInterface.ts, 1, 26))
>C : Symbol(C, Decl(superHasMethodsFromMergedInterface.ts, 0, 0), Decl(superHasMethodsFromMergedInterface.ts, 0, 20))

m3() {
>m3 : Symbol(Sub.m3, Decl(superHasMethodsFromMergedInterface.ts, 2, 21))

super.m2();
>super.m2 : Symbol(C.m2, Decl(superHasMethodsFromMergedInterface.ts, 1, 13))
>super : Symbol(C, Decl(superHasMethodsFromMergedInterface.ts, 0, 0), Decl(superHasMethodsFromMergedInterface.ts, 0, 20))
>m2 : Symbol(C.m2, Decl(superHasMethodsFromMergedInterface.ts, 1, 13))
}
}

24 changes: 24 additions & 0 deletions tests/baselines/reference/superHasMethodsFromMergedInterface.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
=== tests/cases/compiler/superHasMethodsFromMergedInterface.ts ===
class C { m1() { } }
>C : C
>m1 : () => void

interface C { m2(): void }
>C : C
>m2 : () => void

class Sub extends C {
>Sub : Sub
>C : C

m3() {
>m3 : () => void

super.m2();
>super.m2() : void
>super.m2 : () => void
>super : C
>m2 : () => void
}
}

7 changes: 7 additions & 0 deletions tests/cases/compiler/superHasMethodsFromMergedInterface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class C { m1() { } }
interface C { m2(): void }
class Sub extends C {
m3() {
super.m2();
}
}