Angular · TypeScript · Frontend · Migration

Angular Typed Reactive Forms: Migrating from UntypedFormGroup Step by Step

A practical guide to Angular typed reactive forms: what ng update changes, nullable vs nonNullable controls, value vs getRawValue, FormRecord and migrating forms gradually.

Sander Yazıcıoğlu Published: 4 min read Türkçe oku

Angular Typed Reactive Forms: Migrating from UntypedFormGroup Step by Step

When I upgraded large Angular applications across many major versions, version 14 was the step that looked like a no-op and was not. ng update quietly rewrote every FormGroup into UntypedFormGroup, the build stayed green, and the codebase ended up with hundreds of forms that were exactly as untyped as before, now with a longer name. Typed forms only pay off once you actually migrate them. This post is how I did that without a big-bang rewrite.

What changed in Angular 14

Before 14, form.value was any, and form.get('emial') (typo included) compiled fine. Since 14, the form classes are generic:

const form = new FormGroup({
  email: new FormControl('', { nonNullable: true }),
  age: new FormControl<number | null>(null),
});

form.value;          // Partial<{ email: string; age: number | null }>
form.controls.email; // FormControl<string>
form.controls.emial; // compile error

The type is inferred from the initial value, so most forms need no explicit type annotations at all. The migration schematic replaced existing usages with UntypedFormGroup, UntypedFormControl, UntypedFormArray and UntypedFormBuilder, which are aliases of the any-typed versions. That kept upgrades safe, and it is why nothing improved by itself.

Why controls are nullable by default

A plain new FormControl('') is typed FormControl<string | null>, which surprises everyone. The reason is reset(): by default, resetting a control sets it to null, not to its initial value. Angular types that honestly.

Use nonNullable: true when the control should reset to its initial value instead:

const name = new FormControl('', { nonNullable: true });
name.reset();   // value is '' again, type is FormControl<string>

With FormBuilder, the nonNullable property applies this to every control in the group:

private fb = inject(FormBuilder);

form = this.fb.nonNullable.group({
  email: ['', [Validators.required, Validators.email]],
  newsletter: [false],
});

My rule: non-nullable by default, and an explicit <T | null> only for fields that truly have "no value yet", such as an optional date or a select with no default.

value vs getRawValue

form.value is typed as Partial<...>, because disabled controls are excluded from it. Code that reads form.value.email will now see string | undefined and the compiler will push you to handle it. If you need every field, including disabled ones, use getRawValue():

const payload = this.form.getRawValue(); // { email: string; newsletter: boolean }
this.api.save(payload);

This was the single biggest source of compile errors during migration, and most of them pointed at real bugs: places that sent undefined to the API when a field had been disabled.

Typing the form once and reusing it

For forms that mirror an API model, define the shape once:

interface ContactForm {
  name: FormControl<string>;
  email: FormControl<string>;
  phone: FormControl<string | null>;
  tags: FormArray<FormControl<string>>;
}

form = new FormGroup<ContactForm>({
  name: new FormControl('', { nonNullable: true }),
  email: new FormControl('', { nonNullable: true }),
  phone: new FormControl<string | null>(null),
  tags: new FormArray<FormControl<string>>([]),
});

Now a child component can accept @Input() group!: FormGroup<ContactForm> and get full autocompletion inside it.

For dynamic keys, such as a permissions matrix built from server data, use FormRecord instead of a FormGroup with an index signature:

const permissions = new FormRecord<FormControl<boolean>>({});
for (const p of perms) {
  permissions.addControl(p.code, new FormControl(false, { nonNullable: true }));
}

A gradual migration plan

Because Untyped* and typed forms can live side by side, the migration fits into normal work:

  1. Ban new untyped forms. Add a lint rule or a code review check that rejects new UntypedFormGroup usages. The count only goes down from here.
  2. Migrate per feature, not per file type. Take one feature module, convert its forms, fix the compile errors, and run its tests. The component testing guide covers how to keep those tests meaningful.
  3. Start with forms that send data to the API. That is where value vs getRawValue bugs hide.
  4. Replace form.get('a.b') with form.controls.a.controls.b. String paths are still allowed but lose type information.
  5. Track the remaining count with a simple grep -r "Untyped" src | wc -l in CI, so progress is visible.

If you are already doing a gradual strict mode migration, do typed forms alongside it. strictNullChecks is what makes the null in FormControl<string | null> meaningful; without it, much of the benefit disappears.

Common errors and their fixes

ErrorCauseFix
Type 'string | null' is not assignable to 'string'Control is nullablenonNullable: true or handle null
Object is possibly 'undefined' on form.value.xvalue is PartialUse getRawValue()
patchValue accepts wrong keys silentlyIt was any beforeFix the call; the error is real
Template formControlName typo still compilesTemplates are not checked against form typesPrefer [formControl]="form.controls.x" in critical forms

The last row is worth knowing: typed forms check TypeScript code, not string names in templates. Binding with [formControl] gives you checking there too, at the cost of slightly more verbose markup.

Where signals fit

Typed reactive forms remain the stable, recommended API for complex forms. valueChanges is an Observable, and toSignal(form.controls.email.valueChanges) bridges it into signal-based components when you need it. The trade-offs between the two models are covered in Angular Signals vs RxJS.

Conclusion

Typed forms are one of the most useful changes in the Angular upgrade path, but ng update only gives you the option. Use nonNullable by default, read payloads with getRawValue(), define shared form interfaces, and migrate one feature at a time while blocking new untyped code. The compile errors you hit on the way are mostly real bugs that were already in production.

All articles →