One scenario I'm working on involves creating multiple custom formgroup classes that have FormGroup as their parent class, structured like this:
export class CustomFormGroup1 extends FormGroup {
//custom properties for this FormGroup
constructor() {
super(
{
// initializing CustomFormGroup1's form properties
}
);
}
}
export class CustomFormGroup2 extends FormGroup {
//custom properties for this FormGroup
constructor() {
super(
{
// initializing CustomFormGroup2's form properties
}
);
}
}
// and similar classes with unique characteristics
My goal is to place these classes in an array where the type is FormGroup, as shown here:
formList: FormGroup[] = [CustomFormGroup1, CustomFormGroup2, ...etc]
However, when attempting this, I encounter the following error message:
TS2740: Type 'typeof ResourceTypeForm' is missing the following properties from type 'FormGroup': controls, registerControl, addControl, removeControl, and 57 more.
I've searched for solutions and came across similar inquiries such as: Type 'AbstractControl' is missing the following properties from type 'FormGroup': controls, registerControl, addControl, removeControl, and 3 more or TypeScript type of array with common Classes that inherit from same Class but none specifically addressing my particular issue.
In essence, my question is: Is there a way to define an array with objects sharing the same parent class?
While I could potentially implement all the methods for FormGroup
within each custom form group class, I am hoping for a solution that avoids that redundancy.
I have also attempted defining it like this:
formArray: (FormGroup|CustomFormGroup1|CustomFormGroup2|..etc)[] = [CustomFormGroup1, CustomFormGroup2, ...etc];
Yet, I receive the same warning mentioned earlier.
Thank you for any insights you may provide.
Appreciate your assistance.