After finding a different question, I ended up here pondering over a new one.
The original query that brought me here was: Why is form: FormGroup showing 'controls' as undefined in an Angular11 component?
The solution seemed to involve changing this snippet (ngSubmit)="send(newMaterialFormGroup.value)"> to (ngSubmit)="send(newMaterialFormGroup)">
By passing the object itself, I was able to access controls successfully.
However, the fundamental question still lingers...
This is how it looks on the component side:
send(form: FormGroup): void{
let jsonModel = {
materialNum: form.controls['materialNum'].value,
};
let jsonModelRaw: string = JSON.stringify(jsonModel);
//...
}
I'm working with "typescript": "~4.1.5"
Despite explicitly stating that the parameter was of type FormGroup
and having strict typing enabled in TypeScript settings, why did TS fail to detect this issue?