Description
TypeScript appears to treat class methods as something fundamentally different from a class prototype property of type function. This is not in agreement with the standard semantics of ES6.
TypeScript Version: all versions, as far as I have been able to test.
Search Terms: method member property any parent class subclass
Code
class Super {
prop: any;
}
class Derived extends Super {
prop() {}
}
Expected behavior: should compile without a problem. Note that by the ES6 standard, the above definition of Derived
is equivalent to the following, which TypeScript compiles without a problem:
class Derived extends Super {}
Derived.prototype.prop = function(){};
Actual behavior:
Error TS2425: Class 'Super' defines instance member property 'prop', but extended class 'Derived' defines it as instance member function.
Related Issues: I didn't find similar issues, although I started by looking for issues requesting for the ability to disable particular errors (TS2425 in this case). There are several (closed) issues in which such an ability is requested or suggested, but I believe the proper solution would be to bring TypeScript in agreement with ES6. After all, it claims to be a superset!