I have created a class with the following structure:
@Injectable FooService {
constructor(protected _bar:BarService){
}
}
Then, I extended this class as shown below:
@Injectable ExtFooService extends FooService {
constructor(_bar:BarService){
super(_bar);
}
}
However, I decided to further extend the BarService class like so:
@Injectable ExtBarService extends BarService {
public myBarVar = "myBarVar";
constructor(){
super();
}
}
Now, in another part of my codebase:
@Injectable ExtFooService extends FooService {
constructor(_bar:ExtBarService){
super(_bar);
}
someMethod(){
return {
key: this._bar.myBarVar
};
}
}
But suddenly, an error pops up:
Error:(51, 28) TS2551:Property 'myBarVar' does not exist on type 'BarService'.
It seems that ExtBarService is being treated as a BarService because of the superclass requirements. Could there be a solution?
@Injectable ExtFooService extends FooService {
constructor(_bar:BarService, private _extBar: ExtBarService){
super(_bar);
}
someMethod(){
return {
key: this._extBar.myBarVar
};
}
}