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
(I did search for this bug, but could not find it. Sorry if I missed anything).
TypeScript Version: 2.5.2
Code
classClassA{val: number=2;}// Works as expectedclassClassBextendsClassA{constructor(){super();this.val=this.val+1;// this.val type check works as expected}}// Error as expectedclassClassCextendsClassA{val="hello";// <-- Error as expected, can't set string as ClassA.val is number}// Wrong ERROR (IMO) Should be equivalent to ClassBclassClassDextendsClassA{val=this.val+1;// <-- ERROR: 'val' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.}
Expected behavior:
ClassD should be the equivalent as ClassB.
// this.val should be of type "number" as defined in base class (as recognized in ClassB).classClassDextendsClassA{val=this.val+1;// <-- should be the exact equivalent as `ClassB`, this.val should be of the typeof BaseClass.val}
Actual behavior:
// Wrong ERROR (IMO) Somehow assignment of "this.val" make "val" of type any now (but worked fine in ClassB)classClassDextendsClassA{val=this.val+1;// <-- Wrong ERROR: 'val' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.}
Practical usecase
While simple re-assigning might seems uncommon, base property augmentation can be common, and the direct class property make the class more tierce.
Our basic example is as follow:
// base.tsexportclassBaseView{events: EventBindings={};config: Config={};}// mono type assignexportfunctionassign<Textendsobject>(a: T,b: T): T{returnObject.assign(a,b);}
// SubView.tsimport{assign,BaseView}from'base';exportclassSubViewextends{events=assign(this.events,{// <-- Unfortunately, type error here, "this.events" has become "any""click": ()=>{/* do something */}}config=assign(this.config,{// <-- Unfortunately, type error here, "this.config" has become "any"modal: true}}
Right now, we put those "augmentations" in constructosr, but would be nicer if we can just have them as direct property assignment.
The text was updated successfully, but these errors were encountered:
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
(I did search for this bug, but could not find it. Sorry if I missed anything).
TypeScript Version: 2.5.2
Code
Expected behavior:
ClassD
should be the equivalent asClassB
.Actual behavior:
Practical usecase
While simple re-assigning might seems uncommon, base property augmentation can be common, and the direct class property make the class more tierce.
Our basic example is as follow:
Right now, we put those "augmentations" in constructosr, but would be nicer if we can just have them as direct property assignment.
The text was updated successfully, but these errors were encountered: