Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk4 min

Angular Template Type Checking: Enable Strict Checks and Fix Errors

Angular template type checking runs during compilation. Learn what strictTemplates adds, where to configure it, and how to investigate nullability, input, and NG8107 errors.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Angular checks template expressions and bindings during compilation, using TypeScript’s type checker in the AOT template-checking phase. To catch more than basic expression mistakes—including input type mismatches, nullable values, and event types—enable strictTemplates in the application’s angularCompilerOptions, then fix diagnostics against the types and Angular version your project actually uses.

What Angular template type checking does

Template type checking validates expressions and bindings at compile time. Angular reports template type errors during compilation, much like TypeScript reports errors in a .ts file. This catches incompatible values before they become runtime problems, but the amount of checking depends on the project’s template-checking mode and options.

As an Amazon Associate I earn from qualifying purchases.

Angular’s AOT compiler uses TypeScript to validate template bindings. The AOT compilation guide describes how template constructs can narrow types, while the template type checking guide explains the available modes and strictness controls.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

How to enable strict template checking

  1. Open the TypeScript configuration used by the Angular application. Check the app-specific configuration and any configuration it extends; a value in a root file may be overridden in a more specific file.

  2. Under angularCompilerOptions, set strictTemplates to true:

    {
      "angularCompilerOptions": {
        "strictTemplates": true
      }
    }
  3. Run the project’s normal Angular build or compilation command and address the reported template diagnostics. For editor feedback while you work, use the Angular Language Service.

The current Angular compiler-options reference lists strictTemplates as defaulting to true. Do not infer the effective setting from that default alone: older Angular versions, inherited configuration, and explicit overrides can change what your project checks.

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

What strictTemplates checks that basic mode does not

Angular calls the mode with strictTemplates: false basic mode. It checks top-level expression properties, but leaves important parts of the template less constrained. Strict mode improves type information and coverage across embedded views and bindings.

Area Basic mode Strict mode
Embedded views, such as those created by structural directives Not checked Checked
Component or directive input assignability Does not verify that the final expression can be assigned to the input Verifies input assignability
Nullability on inputs Does not provide strict null checking for input bindings Follows TypeScript’s strictNullChecks through strictNullInputTypes
Pipes and local references Does not infer several pipe-result and local-reference types Infers pipe and local-reference types
Events and generic types Does not infer several event types or component and directive generics Infers event types, generics, and template contexts

Because strict mode preserves more type information, it can reveal problems that basic mode did not report. That does not automatically mean the diagnostic is a false alarm: check the expression, the receiving input’s declared type, and the data supplied to the component.

How to diagnose a template type error

Read the expression and expected type together

For an input error, compare the value in the parent template with the input type declared by the child component or directive. A nullable value, for example, cannot safely be passed to an input that accepts only a non-null value unless the template or component design guarantees that value is present.

Make nullability explicit where the value is used

If a value is available only under a condition, express that condition in the template so Angular can narrow the type in the relevant view. Angular documents this behavior for NgIf. For newer built-in control flow, use syntax supported by the project’s Angular version and confirm that the condition establishes the needed type narrowing.

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

For example, a nullable user can be guarded before its properties are accessed:

<div *ngIf="user">
  {{ user.name }}
</div>

Check library declarations and event assumptions

A diagnostic can expose a mismatch in a library declaration as well as in application code. Angular notes that incomplete typings, or declarations that are not strict about nullability, can cause false positives. DOM event types also deserve care: $event.target may be broad because an event can bubble from a descendant, so it may not have the specific element type your code assumes.

Use an escape hatch only for a real invariant

Prefer correcting the type or making the relevant condition visible to the template checker. If the value is known to be present for a reason the type system cannot express, use a narrow workaround and make sure it reflects reality at runtime.

  • $any(expression) casts one expression to any, removing type checking for that expression.
  • strictNullInputTypes: false relaxes null checks for input bindings across the application.
  • strictTemplates: false turns off strict template checking broadly and loses the additional coverage described above.
  • A non-null assertion suppresses a nullability incompatibility. Use it only when the value is genuinely guaranteed to be present.

Angular also documents focused flags for input types, attribute types, safe-navigation types, DOM local-reference types, output and DOM event types, context generics, and literal types. For example, strictInputTypes controls input type checking, while strictDomEventTypes controls checking of DOM event types. Change only the option corresponding to the specific limitation rather than disabling strict checking as a first response.

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

What NG8107 means

Extended diagnostics are emitted when strictTemplates is enabled. NG8107: Optional chain not nullable warns when optional chaining is used on a receiver whose type excludes both null and undefined. In that case, the chain has no effect and may signal that the declared type does not match how the template treats the value. Check whether the type should allow null or whether the optional chain is unnecessary.

Angular safe-navigation behavior depends on version

Confirm your Angular version before drawing conclusions from a template expression that uses optional chaining. The current expression syntax guide says that, since Angular 22, template optional chaining returns undefined when its left side is null or undefined, matching standard JavaScript semantics. During migration, Angular added $safeNavigationMigration to existing expressions to preserve legacy behavior that returned null. Angular describes that migration aid as temporary and recommends avoiding reliance on the distinction between null and undefined.

Get template diagnostics in the editor

The Angular Language Service provides template completions, diagnostics, quick info, and navigation for inline and external templates. Angular recommends using it with strict template checking for earlier feedback as you edit. See the Angular Language Service guide for its capabilities and setup information.

If a diagnostic remains after checking the types, version, and documented options, Angular notes that the template checker itself may have a bug. In that case, report the issue with a small reproducible example rather than making basic mode the default workaround.

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

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
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

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.