Why did TypeScript 4 transpiler not see this incorrect type passed to function?

  angular, typescript, typescript-generics

I had a different question which now lead me to this one here.

My original question was this:
Why is form: FormGroup showing ‘controls’ as undefined in an Angular11 component?

So this piece (ngSubmit)="send(newMaterialFormGroup.value)"> should be
changed to (ngSubmit)="send(newMaterialFormGroup)">

Doing so passes the object and thus allowing me to access controls

But the question remains…

Here is the component side:

send(form: FormGroup): void{
    let jsonModel = {
      materialNum: form.controls['materialNum'].value,

    let jsonModelRaw: string = JSON.stringify(jsonModel);

I’m using "typescript": "~4.1.5"

Why didn’t TS detect this if I stated explicitly that the parameter was of type FormGroup and I have strict typing enabled in TypeScript settings.

Source: Angular Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.