#Satisfying implementation requirements of abstract classes in mixins

5 messages · Page 1 of 1 (latest)

winged forum
#

Consider the following:

abstract class A {
  abstract a: number;
}

abstract class B extends A {
  a = 1;
}

function myMixin(Base: typeof A) {
  abstract class Mixed extends Base {}
  return Mixed;
}

class MA extends myMixin(A) {} // (expected) Non-abstract class 'MA' does not implement ...

class MB extends myMixin(B) {} // (unexpected) Non-abstract class 'MB' does not implement ...

Is there a theoretical reason by MB shouldn't compile? I looked among the typescript issues on github and saw some comments suggesting there might be, but the discussions were a little over my head.

fading frigate
#

You're telling TS that Base is A, so the return of the function is considered to be A

#

You need a generic to capture the type of the input class

#

!hb generic

errant baneBOT