Last time I learned how to make a typing script see methods copied into a class prototype from another place. All methods were reduced to the declaration of field types:
class First { someMethod() { console.log('someMethod from First'); } } function Second() { console.log('Second'); } Second.prototype.doSmth = function () { console.log('doSmth from Second'); } class Both extends First { constructor() { console.log('constructor of Both'); super(); Second.call(this); } doSmth: () => void } for (let key in Second.prototype) { Both.prototype[key] = Second.prototype[key]; } class Final extends Both { doIt() { this.someMethod(); this.doSmth(); Both.prototype.doSmth(); // ok Final.prototype.doSmth(); // ok } } However, it now took one of the heirs to override this method:
class OtherFinal extends Both { doSmth() { // Здесь ошибка console.log('doSmth from OtherFinal'); } } Class 'Both' defines an instance member property
Actually, the message is quite logical.
But how else can you make typescript see a method that is not explicitly stated in it?
All methods lead to the same problem (links lead to the corresponding fiddly):doSmth: () => void , doSmth: typeof Second.prototype.doSmth; .
It is clear that you can declare the function doSmth() {} , but in this case the garbage gets into the compiled code, so I don’t want to do that.