typed-trait icon indicating copy to clipboard operation
typed-trait copied to clipboard

What is super?

Open mohsen1 opened this issue 7 years ago • 1 comments

First of all, amazing work! This solves a real problem.

Consider this:

class A {
        constructor(private foo = () => 'A') {

        }
}

class B {
        constructor(private foo = () => 'B') {}
}

class C extends mixin(A, B) {}

TypeScript is already complaining:

    Property 'foo' has conflicting declarations and is inaccessible in type 'C'.

I'm confused what would be super when you extending mixins

mohsen1 avatar Apr 15 '18 00:04 mohsen1

Thanks @mohsen1! To get constructors to work, mixin() would have to synthesize a linear prototype chain. I feel sort of meh about doing that, because it means (1) constructing mixed in classes may produce side effects because constructor code will run, and (2) order of mixins now matters because it specifies the order in which constructors are run. That said, these are things that people probably expect from mixins, and if this lib doesn’t do those things, I should probably rename it “magical-traits” :).

bcherny avatar Apr 15 '18 01:04 bcherny