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
Faulty declarations file from extending generic base class #17805
Mohamed Hegazy (@mhegazy) The example in the OP is (correctly) an error nowadays: Base class expressions cannot reference class type parameters, thanks to #17922. If the OP is still active and curious why, see the discussion in #17829 which is somewhat similar to this.
@NorlAbrahams referencing class type parameters in the extends clause doesn't make sense - the extends clause is executed once (to find the base class), but the type parameters are reinstantiated on every constructor call. If the goal is to pass on the generic into the extending class, that's still possible (ie, extending a generic base class), it's just not possible to use the type parameters in the actual extends clause expression, since they'll never be instantiated with real types there.
I don't understand why did you do that ? This was only single way to create generic mixins. Now I can't migrate to 2.8 because there is no alternative for this feature
This code works perfect in 2.3.2
// The goal to add generic method via mixin functionValidatorMixin<Textends{new(...args: any[]): {}},V>(BaseClass: T,validate: (arg: V)=>boolean){abstractclassValidatorextendsBaseClass{value: V;validate(value: V){returnvalidate(value);}}returnValidator;}classBaseInput{}classStringInput<T=string>extendsValidatorMixin(BaseInput,(value: T)=>typeofvalue==='string'){}// ValidatorValueType will be string | null | undefinedtypeValidatorValueType=StringInput<string|null|undefined>['value'];
And now it has thrown an error. Yes there is a problem with extending static properties, but maybe you could make this check opinionated via additional flag like for strict generic
Activity
weswigham commentedon Mar 20, 2018
Mohamed Hegazy (@mhegazy) The example in the OP is (correctly) an error nowadays:
Base class expressions cannot reference class type parameters, thanks to #17922. If the OP is still active and curious why, see the discussion in #17829 which is somewhat similar to this.weswigham commentedon Mar 21, 2018
@NorlAbrahams referencing class type parameters in the extends clause doesn't make sense - the extends clause is executed once (to find the base class), but the type parameters are reinstantiated on every constructor call. If the goal is to pass on the generic into the extending class, that's still possible (ie, extending a generic base class), it's just not possible to use the type parameters in the actual extends clause expression, since they'll never be instantiated with real types there.
NoelAbrahams commentedon Mar 21, 2018
Wesley Wigham (@weswigham) I had already chickened out and deleted my comment. But thanks for the explanation!
mrazorvin commentedon Mar 30, 2018
Hello,
I don't understand why did you do that ? This was only single way to create generic mixins. Now I can't migrate to 2.8 because there is no alternative for this feature
This code works perfect in 2.3.2
And now it has thrown an error. Yes there is a problem with extending static properties, but maybe you could make this check opinionated via additional flag like for strict generic