I wish to pass an injected microservice through the super(); call to parent classes.
Abstract top-level parent class:
export abstract class Crypto {
constructor() {
}
}
2 child classes:
export class BTC extends Crypto {
constructor(
@Inject('COIN_API_SERVICE')
private readonly apiService: ClientProxy, // this is an external microservice
) {
super();
}
}
export class ETH extends Crypto {
constructor(
@Inject('COIN_API_SERVICE')
private readonly apiService: ClientProxy,
) {
super();
}
}
And a child class of a child class:
export class ERC20Token extends ETH {
constructor(
@Inject('COIN_API_SERVICE')
private readonly apiService: ClientProxy,
) {
super();
}
}
Since all ERC20 classes work exactly like ETH instances with a few tweaks, it makes sense to extend it from ETH. However, trying to compile this code ends up in the follow error:
TS2415: Class 'ERC20Token' incorrectly extends base class 'ETH'. Types have separate declarations of a private property 'apiService'.
But I need to make both instances of ETH and ERC20 Token, so both need to have an apiService. How to resolve this issue?