My goal is to ensure that a class implements a method called okClick
, so I decided to use an interface.
interface BaseComponent {
okClick(): void
}
I then created a class that implements this interface.
class ComponentImplementation implements BaseComponent {
okClick(): void {
// ok button clicked
}
}
In order to dynamically create instances of these components using Angular's createComponent()
, I tried storing them in a variable of type BaseComponent
.
class Implementation {
// TS2741: Property 'okClick' is missing in type 'typeof ComponentImplementation' but required in type 'BaseComponent'.
tempVar: BaseComponent = ComponentImplementation
constructor() {
// dynamically create the Angular component from tempVar
}
}
However, the assignment of the class to the variable tempVar
fails to recognize the okClick
function.
I would appreciate any suggestions on how to define the type of tempVar
to correctly hold classes implementing the BaseComponent
interface.