I am struggling with defining a method to take subclasses of a base class correctly.
handle(content: AbstractClass)
Calling it directly with an inherited class leads to Argument of type 'ConcreteClass' is not assignable to parameter of type 'AbstractClass'.
I have tried it with an interface, similar result Argument of type 'typeof ConcreteClass' is not assignable to parameter of type 'Interface'
class AbstractClass implements Interface
handle(content: Interface)
I have found a question to a similar topic but the solution also don't helps me.
interface ClassConstructor<T extends AbstractClass> {
new(): T;
}
abstract class AbstractClass {
private test: string;
constructor(value: string) {}
}
class B extends AbstractClass {
private test2: string;
constructor(value: string, value2: number) {
super(modal);
}
}
class S1 {
show(content: ClassConstructor<AbstractClass>) {}
b() {
this.a(B);
}
}
On playground
I want to achieve that the method show
can take every implementation of the AbstractClass regardless how it is defined f.e. different constructors and similar.
I am using it in combination with Angular and Angular resolves dependencies via the constructor.
How can I do this with TypeScript?