Full answer
Since Angular 14, FormControl<T>, FormGroup<{...}> and FormArray<T> carry types.
Key rules:
new FormControl('')has typeFormControl<string | null>, becausereset()sets the value tonull. Usenew FormControl('', { nonNullable: true })so reset goes back to the initial value, and the type isstring.FormBuilder.nonNullable.group({...})applies this to all controls.group.valuehas typePartial<{...}>, because disabled controls are not included.group.getRawValue()includes disabled controls and has the full type.form.controls.nameis typed, and a wrong name is a compile error.form.get('name')is typed for simple paths in newer versions, butcontrolsis clearer.FormRecord<T>is for dynamic keys with the same type.FormArray<FormControl<string>>for lists.UntypedFormGroupexists for migration only.
A helper: give a plain model ({ name: string; marks: number }) and get a typed form where each property is a non-nullable control:
type ControlsOf<T> = { [K in keyof T]: FormControl<T[K]> }
function formFor<T extends Record<string, unknown>>(model: T): FormGroup<ControlsOf<T>> creates a FormControl(value, { nonNullable: true }) for each key. This keeps types in one place and avoids repeating them.
Limits: nested groups and arrays need recursive types, which makes types hard to read. For nested forms, build small typed sub forms and compose them. Do not make the type too clever, because error messages become hard to read for the team.
Submit pattern: if (form.invalid) return; const value = form.getRawValue(); gives a fully typed object to send to the server. Map to a DTO type explicitly, so form shape changes do not silently change the API.
import { FormControl, FormGroup } from '@angular/forms';
type ControlsOf<T> = { [K in keyof T]: FormControl<T[K]> };
export function formFor<T extends Record<string, string | number | boolean>>(model: T): FormGroup<ControlsOf<T>> {
const controls = {} as ControlsOf<T>;
for (const key of Object.keys(model) as (keyof T)[]) {
controls[key] = new FormControl(model[key], { nonNullable: true }) as ControlsOf<T>[keyof T];
}
return new FormGroup(controls);
}
interface StudentModel extends Record<string, string | number | boolean> {
name: string;
marks: number;
}
const form = formFor<StudentModel>({ name: 'Asha', marks: 72 });
const marks: number = form.controls.marks.value; // number, not number | null
const raw: StudentModel = form.getRawValue(); // full type, includes disabled controls
// form.controls.age; // compile error: no such control
form.controls.marks.disable();
const partial: Partial<StudentModel> = form.value; // marks is missing at run time
console.log(marks, raw, partial);Angular 20.3 strict mode, type-checked with `ngc`. The assignments in the example are checked by the compiler. The helper itself was not unit tested.
Key points
- `FormControl<string | null>` by default. Use `nonNullable` to get `string` and keep the initial value on reset.
- `value` is Partial because of disabled controls. `getRawValue()` is the full type.
- A mapped type `ControlsOf<T>` plus a helper builds typed forms from a model.
- Keep types simple. Map form values to a DTO explicitly.
Common mistakes
- Forgetting `nonNullable` and getting `null` after reset.
- Using `value` and expecting all keys.
- Using `UntypedFormGroup` to avoid type errors.
Follow-ups
- What is the difference between `FormRecord` and `FormGroup`?
- How would you type a nested group?
- Why map the form value to a DTO?
Tips
- Explain the reset to null reason.
- Show the mapped type.
- Say you keep types readable.
Evaluation rubric
- Explains null handling, Partial value and getRawValue.
- Writes a correct generic helper.
- Gives practical typing advice.