support for class-factory mixins
See original GitHub issueThe following plain JS doesn’t work:
function Foo(Base) {
return class Foo extends Base {
foo() { console.log('foo') }
}
}
class Bar {
bar() { console.log('bar') }
}
class Baz extends Foo(Bar) {
baz() { console.log('baz') }
}
const b = new Baz
b.foo()
b.bar()
b.baz()
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:5 (1 by maintainers)
Top Results From Across the Web
feature request: support for mixins composed from other ...
I'm porting JavaScript code to TypeScript, and the JavaScript makes great use of mixins (including composing new mixins from other mixins), but ...
Read more >Class::MixinFactory - Class Factory with Selection of Mixins ...
Factories support methods that control which classes they will use. The base class will be inherited from by all mixed classes. $factory -> ......
Read more >Typescript Mixin with Class Factory - Stack Overflow
I have a Class factory that has been derived from creating a class using typescript with specific fields, but I'd like to do...
Read more >Multiple inheritance (not class-factory mixins). Will it ever be a ...
I don't like class-factory mixins, because they require wrapping classes in functions. Therefore, one can not import a 3rd-party class and compose it....
Read more >Factory(3pm) — libclass-mixinfactory-perl — Debian unstable
Class::MixinFactory::Factory - Class Factory with Selection of Mixins ... A mixin factory generates new classes at run-time which inherit ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As another example of the current complexity, here’s my Mixin implementation (which itself isn’t that long) and the unit tests (but the README has better more practical examples). But it gets complicated at the usage sites, for example.
It is riddled with issues. For example, in that last example, if I change the lines
to
it completely breaks (for no intuitive reason). The
Constructor(Base)
constructor expression must be assigned to a new variable first, for it to work.It’s little things like that, plus all the other issues like having to follow the patterns with the mapped typed that you see in that example, that make it all too complicated compared to plain JS.
I’m also interested in class mixins, and the developer experience with TypeScript has been quite painful in this regard.
Here is one more issue which wasn’t mentioned above: microsoft/TypeScript#17744. See my comment there for an overview of techniques that I tried, including the workaround for using protected methods.
Generally, this might be beneficial for web components libraries, such as Lion, Vaadin, Spectrum and others. We have to use class mixins when creating custom elements classes that extend
HTMLElement
.