When working with Angular, there is a need to specify the type for a component that implements a particular interface and is passed into a class.
For example, consider Class A with the following signature:
class A {
constructor(public component: ?) {}
}
We then declare an interface I as follows:
export interface I<T> {
setData(data: T): void;
}
The component B is one such implementation of interface I:
class B implements I<string> {
setData(data: string) { ... }
}
The challenge arises when multiple components - C, D, and E also implement interface I. Class A should be able to process all these components. Is it possible to specify in class A that the component type can be any component that implements interface I? Currently, using
component: any
solves the issue but leaves room for improvement. Ideally, we would like to define it as any component that implements interface I. Is there an alternative approach to achieve this?