-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Description
TypeScript Version: 3.2.2
Search Terms: property inheritance constructor super
Code
abstract class A {
public names = ['A'];
}
class B extends A {
public names = [...super.names, 'B'];
}
const b = new B();
alert(b.names);
Expected behavior:
ES2015+ target: either TypeScript downlevels super.names
in the child class to this.names
which would make that code work, or it should give an error like it does in the ES5 version (check playground link).
Working ES2015 version:
class A {
constructor() {
this.names = ['A'];
}
}
class B extends A {
constructor() {
super(...arguments);
this.names = [...this.names, 'B']; // `super` -> `this` so that this works as expected, but maybe not correct, not sure of the implications.
}
}
const b = new B();
alert(b.names);
So either that, or give a compile error. (ES5 target gives a compile error that has nothing to do with the actual error, so maybe even that should be sorted out)
Actual behavior:
Compiles fine under ES2015+ target, but gives a runtime error. (check stackblitz link)
Stackblitz Link: https://stackblitz.com/edit/typescript-jcg479
Related Issues: I've tried, but couldn't really find anything similar. Forgive me if it has been reported already.