Typescript: How to extend two classes?

前端 未结 9 1090
猫巷女王i
猫巷女王i 2020-11-29 22:38

I want to save my time and to reuse common code across classes which extends PIXI classes (a 2d webGl renderer library).

Object Interfaces:

9条回答
  •  温柔的废话
    2020-11-29 23:13

    TypeScript supports decorators, and using that feature plus a little library called typescript-mix you can use mixins to have multiple inheritance with just a couple of lines

    // The following line is only for intellisense to work
    interface Shopperholic extends Buyer, Transportable {}
    
    class Shopperholic {
      // The following line is where we "extend" from other 2 classes
      @use( Buyer, Transportable ) this 
      price = 2000;
    }
    

提交回复
热议问题