-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Closed
Copy link
Labels
Milestone
Description
Bug Report
🔎 Search Terms
- used before extends
- property initialization base
- useDefineForClassFields initialization
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about useDefineForClassFields
⏯ Playground Link
Playground link with relevant code
💻 Code
// @useDeclareForClassFields: true
class Base {
a = 1;
b = 1;
c = 1;
d = 1;
e = 1;
}
class Derived extends Base {
a = 2;
b;
declare c: number;
d: number = this.a /*2*/ + this.b /*undefined*/ + this.c /*1*/ + this.d /*1*/ + this.e /*1*/; // expected error on 'b', all other are valid
e;
constructor() {
super();
this.b = 2;
this.e = 2;
}
}🙁 Actual behavior
No error in the code above. Use-before-def allows access to properties of the base class, even if the current class redeclares that property.
This is correct until you enable useDefineForClassFields. Then the redeclaration of b overrides the base class property before the access. I added comments containing the runtime values.
🙂 Expected behavior
ais allowed because it's initializedbis a use-before-def errorcis allowed because of thedeclaremodifierdis allowed to access the base class property in the initializer becaues at that point its value is not overridden yeteis allowed because its value is overridden after accessing it.
/cc @sandersn