Is it possible to make the membervar
of class Parent
generic instead of type any
, while still retaining the ability to switch provider classes without having to update all components that rely on class Parent
? For example, if class ChildB
implements a different type for class Parent
than class ChildA
.
export abstract class Parent {
membervar: any;
}
export class ChildA extends Parent {
constructor() {
super();
this.membervar = ObjectA();
}
}
export class ChildB extends Parent {
constructor() {
super();
this.membervar = ObjectB();
}
}
In my app.module.ts, I can change the provider class by:
...
providers: [ { provide: Parent, useClass: ChildA } ]
...
There are components in the application that depend on the above structure:
export class SomeComponent {
constructor(private aService: Parent) {
}
}
export class SomeOtherComponent...
constructor(private aService: Parent)...