Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk3 min

How to Use Strictly Typed Reactive Forms in Angular

Angular reactive forms are strictly typed by default from Angular 14. Learn how to choose form containers and handle nullable resets, optional controls, and disabled values.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Angular reactive forms are strictly typed by default from Angular 14 onward. Use FormGroup for a known set of controls, FormArray for a changing list of similar controls, and FormRecord for changing keys that share a control type. Two runtime details matter especially: a control may be nullable because reset() can set it to null, and a group’s value may omit disabled controls. The official Angular guide covers these rules at Strictly typed reactive forms.

What strict typing changes in reactive forms

Angular’s typed forms model the controls and their values in TypeScript, giving compile-time checks and IDE autocomplete. For example, if a control holds a string, TypeScript will reject code that tries to read a string-only value as though it had a domain property. These typing improvements apply to reactive forms, not template-driven forms. Angular’s forms overview describes reactive forms as an explicit model with observable streams, suited to scalable, reusable, and testable form logic; template-driven forms can suit basic forms managed in the template. See Angular Forms overview and Reactive forms.

As an Amazon Associate I earn from qualifying purchases.

For migration or code that cannot yet be typed reliably, Angular retains the Untyped APIs, such as UntypedFormGroup and UntypedFormArray. They allow gradual adoption, but do not provide the same compile-time guarantees.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose a control container based on its shape

Container Use it when Typing implication
FormGroup The form has a known set of named controls. Declare the control keys and their types. Optional control properties can represent controls that may be present only sometimes.
FormArray The form has a dynamic list whose controls share a type. Its elements are homogeneous. For a list with different control types in different positions, use UntypedFormArray.
FormRecord Control names are dynamic, but controls share a type. Use it for dynamically named controls with a common control/value type.
UntypedFormGroup The group is fully dynamic and heterogeneous. Angular notes that this shape has no improved type safety, so an untyped group is appropriate.

In a typed FormGroup, declaring a control as optional is the type-safe way to express that it may be added or removed. TypeScript then limits those operations to controls declared optional. The current typed forms guide explains these container choices; the FormGroup API reference documents the group API.

Account for null when a control resets

A control initialized with a string is inferred as FormControl<string|null>, not just FormControl<string>. That is because calling reset() without a replacement value can set the control’s value to null. Code that reads the value must handle that possibility.

Set nonNullable: true when the control should stay non-nullable. This is not only a TypeScript annotation: it changes runtime reset behavior. Resetting such a control returns it to its initial value instead of making its value null. Choose the behavior that matches what the form should do, rather than suppressing nullability just to quiet a type error. Angular documents the inference and reset behavior in its strictly typed forms guide.

NonNullableFormBuilder is shorthand for applying non-nullable behavior to the controls it creates. Use it when that reset policy is appropriate across the controls being built; controls created without that behavior should not be assumed non-nullable.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Know what a group’s value includes

A typed group’s .value can be partial because disabled controls are omitted from that value. As a result, a field may be undefined even if it is part of the group’s declared shape. Consumers should account for that possibility when using .value.

Use getRawValue() when the result needs to include disabled controls. The choice is about the data the consumer requires: enabled controls only, or all controls including disabled ones. Angular describes this distinction in the typed forms guide.

A practical decision sequence

  1. Identify the shape. Use FormGroup for fixed named keys, FormArray for a dynamic homogeneous sequence, or FormRecord for dynamic keys with a shared control type.
  2. Model variability. Mark controls optional in a group’s type if they may be added or removed. If the collection is heterogeneous and cannot be represented safely, use the corresponding untyped API.
  3. Decide reset semantics. Keep nullable controls if reset may produce null; choose non-nullable controls if reset should restore the initial value.
  4. Choose the value shape the consumer needs. Use .value when omission of disabled controls is appropriate; use getRawValue() when disabled values must be included.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.