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
Roughly the static part of a class is a singleton (and doesn't vary), so you can't do something like class A<T> extends B<T>. The workaround is to declare the class independently.
exportconstSampleMixin1=<TextendsAnyConstructor<object>>(base : T)=>classSampleMixin1extendsbase{another: SampleMixin2// TS2502: 'another' is referenced directly or indirectly in its own type annotation}exporttypeSampleMixin1=Mixin<typeofSampleMixin1>exportconstSampleMixin2=<TextendsAnyConstructor<object>>(base : T)=>classSampleMixin2extendsbase{another: SampleMixin1// TS2502: 'another' is referenced directly or indirectly in its own type annotation}exporttypeSampleMixin2=Mixin<typeofSampleMixin2>// supporting declarations for mixin patternexporttypeAnyFunction<A=any>=(...input: any[])=>AexporttypeAnyConstructor<A=any>=new(...input: any[])=>AexporttypeMixin<TextendsAnyFunction>=InstanceType<ReturnType<T>>
Workaround seems to be to create an interface which extends the typeof for the class and use that. This isn't something we love, but it makes sense.
I found both the issue on recursive mixing referencing and the DTS output to not really be an issue with the class expression pattern and so I've not added them to the constraints
Does this issue consider the use of protected and private within class-factory mixins? I recall that the type workarounds don't work because mapped types can not handle protected/private properties.
Mixin Docs Today
Some folks have looked to improve it, and add their own docs:
Mixin goals
Today, how do we recommend it
Currently 2 different implementations strategies:
class
es. Then useinterface
merging + a runtime function to create - playclass
es useextends
with their list of deps - playThere is one library which covers a lot of mixin stuff: ts-mixer (no need to read it, it's mostly the
extends
pattern) - probably worth a sentenceThe 4.0 improvements to tuples could improve the pattern ...maybe?How to describe short-comings
Mixins with Generics - play
Roughly the static part of a class is a singleton (and doesn't vary), so you can't do something like
class A<T> extends B<T>
. The workaround is to declare the class independently.You can move the position of the generics - example and it can work
Recusive definitions
You can write:
But not when it's a mixin pattern:
Workaround seems to be to create an
interface
which extends thetypeof
for the class and use that. This isn't something we love, but it makes sense.Mixins can't be represented in a d.ts file
Mixins can't be made with decorators
Basically a decorator on a class can't mutate the shape of the class, though ts-mixer seems to do this (and you can use
interface
merging too)Notes
The pattern is supported, and used by the Vue community in v1/v2. We think mostly by the mixin factory method.
For orta
The text was updated successfully, but these errors were encountered: