TypeScript: class composition

后端 未结 2 1041
一整个雨季
一整个雨季 2021-02-14 15:42

Based on this awesome Composition over Inheritance video by MPJ, I\'ve been trying to formulate composition in TypeScript. I want to compose classes, not object

2条回答
  •  感动是毒
    2021-02-14 16:20

    Unfortunately, there is no easy way to do this. There is currently a proposal to allow for the extends keyword to allow you to do this, but it is still being talked about in this GitHub issue.

    Your only other option is to use the Mixins functionality available in TypeScript, but the problem with that approach is that you have to re-define each function or method that you want to re-use from the "inherited" classes.

提交回复
热议问题