How should I declare this type ?
Let say I've a FormGroup
export interface MyType {
myValue: string
}
myForm: FormGroup
myArray: FormArray // <FormControl<MyType>>
constructor(private _formBuilder: FormBuilder) {
myForm = new FormGroup({
myArray: this._formBuilder.array([])
})
}
addElement() {
this.myArray = this.myForm.get('myArray') as unknown as FormArray
this.myArray.push(this.newElement())
}
private _newElement(): FormGroup { // What type to use ?
return this._formBuilder.group({
myValue: ''
})
}
But when I do use the
myArray: FormArray<FormControl<MyType>>
I get the following error
Argument of type 'FormGroup<any>' is not assignable to parameter of type 'FormControl<MyType>'.
Type 'FormGroup<any>' is missing the following properties from type 'FormControl<MyType>': defaultValue, registerOnChange, registerOnDisabledChange
Somebody knows
private _newElement(): FormGroup { // What type to use ?
myArray: FormArray<FormControl<MyType>>
? -> FormGroup<FormControl<MyType>>
being incorrectexport class MyTypeForm {
myValue: FormControl<string>;
}
myArray
type as FormArray<FormGroup<MyTypeForm>>
.myArray: FormArray<FormGroup<MyTypeForm>>;
_newElement
method to return FormGroup<MyTypeForm>
type.private _newElement(): FormGroup<MyTypeForm> {
return this._formBuilder.group<MyTypeForm>({
myValue: this._formBuilder.control(''),
});
}