I have a problem trying to check a type in angular.
export interface DynamicComponentConfig {
name: string;
component: Type<any>;
}
export class DynamicInputComponent extends DynamicComponentBase {
}
export class DynamicDatePickerComponent extends DynamicComponentBase {
}
export class DynamicComponentBase {
@Input() group: FormGroup;
@Input() form: FormGroupDirective;
}
When I create an instance which is holding a reference type (not an instance of the type):
let conf: DynamicComponentConfig = {
component: DynamicInputComponent,
name: 'Surname'
};
And pass to a service in charge of creating my component dynamically, I need to check the type, but instanceof is not working:
if (conf.component instanceof DynamicComponentBase) {
...
}
it's only working when I check directly the type it belongs to, but I have several components all of them inherit from DynamicComponentBase:
if (conf.component === DynamicInputComponent || conf.component === DynamicDatePickerComponent || ...) {
...
}
Checking config.component.prototype I get DynamicComponentBase {constructor: ƒ}, but if I check config.component.prototype === DynamicComponentBase I get false
So what I'm looking for is a way to check if they inherit from my base component, any idea?