I wonder if there's any plans to support decorators within mixins?
type Constructor<T> = { new (...args: any[]): T }
function Mixin<T extends Constructor<{}>>(Base : T) {
return class extends Base {
constructor(...args: any[]) {
super(...args)
}
@decorator
get y() {
return this.x + 3
}
}
TSC 2.2.1 currently rejects this construction: [Decorators are not valid here]
We got into same issues here https://github.com/wc-catalogue/blaze-elements/blob/master/packages/common/mixins.ts#L10
the quickfix is easy just define the mixin class and return it afterwards:
type Constructor<T> = { new (...args: any[]): T }
function Mixin<T extends Constructor<{}>>(Base : T) {
class MixinClass extends Base {
constructor(...args: any[]) {
super(...args)
}
@decorator
get y() {
return this.x + 3
}
}
return MixinClass;
}
Ah, Wonderful!
Thanks!
Hmm I would rather keep it open to get core team opinion on this cc @RyanCavanaugh @DanielRosenwasser - if it's desing limitation or bug.
What I suggested is just "hotfix" to not get stuck
thx!
True.
I think the idea that decorators can inform the type system of changes that it may be performing is something we will be considering over time.
Cool so I guess we can close this and reference the hotfix to #7342 ?
Sorry, I misread this. My previous comment has nothing to do with this, but yeah, looks like #7432 seems like the right place to discuss the issue.
Most helpful comment
We got into same issues here https://github.com/wc-catalogue/blaze-elements/blob/master/packages/common/mixins.ts#L10
the quickfix is easy just define the mixin class and return it afterwards: