Skip to content

Commit e45c949

Browse files
Fix to issue 6154 - Overriding a method with a property in the derived class should not cause a compiler error
1 parent a5029e3 commit e45c949

File tree

5 files changed

+83
-1
lines changed

5 files changed

+83
-1
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24430,7 +24430,7 @@ namespace ts {
2443024430
continue;
2443124431
}
2443224432

24433-
if (isPrototypeProperty(base) && isPrototypeProperty(derived) || base.flags & SymbolFlags.PropertyOrAccessor && derived.flags & SymbolFlags.PropertyOrAccessor) {
24433+
if (isPrototypeProperty(base) || base.flags & SymbolFlags.PropertyOrAccessor && derived.flags & SymbolFlags.PropertyOrAccessor) {
2443424434
// method is overridden with method or property/accessor is overridden with property/accessor - correct case
2443524435
continue;
2443624436
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//// [propertyOverridingPrototype.ts]
2+
class Base {
3+
foo() {
4+
}
5+
}
6+
7+
class Derived extends Base {
8+
foo: () => { };
9+
}
10+
11+
12+
13+
//// [propertyOverridingPrototype.js]
14+
var __extends = (this && this.__extends) || (function () {
15+
var extendStatics = Object.setPrototypeOf ||
16+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
17+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
18+
return function (d, b) {
19+
extendStatics(d, b);
20+
function __() { this.constructor = d; }
21+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
22+
};
23+
})();
24+
var Base = /** @class */ (function () {
25+
function Base() {
26+
}
27+
Base.prototype.foo = function () {
28+
};
29+
return Base;
30+
}());
31+
var Derived = /** @class */ (function (_super) {
32+
__extends(Derived, _super);
33+
function Derived() {
34+
return _super !== null && _super.apply(this, arguments) || this;
35+
}
36+
return Derived;
37+
}(Base));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
=== tests/cases/compiler/propertyOverridingPrototype.ts ===
2+
class Base {
3+
>Base : Symbol(Base, Decl(propertyOverridingPrototype.ts, 0, 0))
4+
5+
foo() {
6+
>foo : Symbol(Base.foo, Decl(propertyOverridingPrototype.ts, 0, 12))
7+
}
8+
}
9+
10+
class Derived extends Base {
11+
>Derived : Symbol(Derived, Decl(propertyOverridingPrototype.ts, 3, 1))
12+
>Base : Symbol(Base, Decl(propertyOverridingPrototype.ts, 0, 0))
13+
14+
foo: () => { };
15+
>foo : Symbol(Derived.foo, Decl(propertyOverridingPrototype.ts, 5, 28))
16+
}
17+
18+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
=== tests/cases/compiler/propertyOverridingPrototype.ts ===
2+
class Base {
3+
>Base : Base
4+
5+
foo() {
6+
>foo : () => void
7+
}
8+
}
9+
10+
class Derived extends Base {
11+
>Derived : Derived
12+
>Base : Base
13+
14+
foo: () => { };
15+
>foo : () => {}
16+
}
17+
18+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Base {
2+
foo() {
3+
}
4+
}
5+
6+
class Derived extends Base {
7+
foo: () => { };
8+
}
9+

0 commit comments

Comments
 (0)