I want my FormControl
(FormGroup
/ FormArray
) be strongly typed so when I have e.g.
interface SomeSource {
id: string;
name: string;
}
and I transformed it to e.g.
let form = new FormGroup<SomeSource>({
id: new FormControl('test id'),
name1: new FormControl('test name')
});
TypeScript had thrown an error: the name
is not found on FormGroup
.
Also in the ideal world the form.value
should be of SomeSource
type (and not any
).
Problem is that there is no way to specify this generic type for any AbstractFormControl
child.
I think this is fairly easy to override FormGroup
with an own interface. However, is there a way to achieve this just using Angular? If no, are there third party solutions?
Motivation: I want to easily refactor my SomeSource
. Currently when I refactor SomeSource
interface, the form is not adapted and no error is thrown => there is a room for some bugs.
name1
in your formgroup? – MarguritemargySomeSource
. This is just a typo simulation – Davis