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
This is strongly related to #4881 but I'm not sure if it's feature request or if it's really a bug. Given that the Decorators spec states the decorator can return a new constructor function, it sort of seems like it should work.
The following example uses constructor function types and very nearly works.
interfaceConstructorFunction<T>{new(...args:any[]):T;prototype:T}interfaceDisappearing{isVisible():boolean;vanish():void;}functionDisappearing<T>(ctor:ConstructorFunction<T>):ConstructorFunction<T&Disappearing>{letresult=<ConstructorFunction<T&Disappearing>>ctor;result.prototype.isVisible=()=>{return!this['_hasDisappeared'];};result.prototype.vanish=()=>{this['_hasDisappeared']=true;};returnresult;}// This seems like it should work// @Disappearing// class Cat {// constructor(private name:string) {}// }// but I have to do this
@DisappearingclassCatimplementsDisappearing{constructor(privatename:string){}isVisible(){returnfalse}vanish(){}}// let ctor = wrappedBlah(Cat);letbuster=newCat('Buster');alert(`Is Buster visible? -> ${buster.isVisible()}`);buster.vanish();alert(`Is Buster visible? -> ${buster.isVisible()}`);
The text was updated successfully, but these errors were encountered:
The issue here is that the tyep system is not aware of any type mutations the decoarator does to the original type. #4881 tracks supporting this. This issue is a duplicate of #4881.
for your scenario. you use interface/class merging to get what you want:
This is strongly related to #4881 but I'm not sure if it's feature request or if it's really a bug. Given that the Decorators spec states the decorator can return a new constructor function, it sort of seems like it should work.
The following example uses constructor function types and very nearly works.
View this in playground
The text was updated successfully, but these errors were encountered: