You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Missing use-before-def error for redeclared property present in base class #42319
// @useDeclareForClassFields: trueclassBase{a=1;b=1;c=1;d=1;e=1;}classDerivedextendsBase{a=2;b;declarec: 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 valide;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
a is allowed because it's initialized
b is a use-before-def error
c is allowed because of the declare modifier
d is allowed to access the base class property in the initializer becaues at that point its value is not overridden yet
e is allowed because its value is overridden after accessing it.
There's a very similar issue when a base class property is redeclared as parameter property. Note that this one requires target: ESNext AND useDefineForClassFields:
For this case the error logic needs to be chaned to: if emitting native class fields, it's not allowed to use parameter properties in other property's initializers, regardless of the presence of a base class property with the same name.
Activity
ajafff commentedon Jan 14, 2021
There's a very similar issue when a base class property is redeclared as parameter property. Note that this one requires
target: ESNextANDuseDefineForClassFields:For this case the error logic needs to be chaned to: if emitting native class fields, it's not allowed to use parameter properties in other property's initializers, regardless of the presence of a base class property with the same name.