October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk2 min

Angular NG8107: Key Facts About Optional Chaining and Types

Angular NG8107 flags optional chaining on a value typed as non-nullable. Fix the mismatch by updating the type or removing the unnecessary operator.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Angular’s NG8107 warning means a template uses optional chaining (?.) on a value whose declared type excludes both null and undefined. Check whether the value can really be missing: include the appropriate nullish type and keep ?. if it can, or remove ?. if it cannot.

What NG8107 means

Optional chaining avoids accessing a property when the value to its left is null or undefined. NG8107 appears when Angular’s template type checker says that value cannot be either. In that case, ?. does not protect against a nullish value according to the declared type, and the template may imply a case the type says is impossible. Angular’s guidance is to keep the template and declared type in sync.

As an Amazon Associate I earn from qualifying purchases.

The warning concerns the type Angular sees, not proof that a runtime value can never be missing. Before editing, check where the value comes from, how it is initialized, and whether its lifecycle or data source can leave it nullish.

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

Choose the fix that matches the value

There are two valid corrections. Use the one that reflects the actual data contract.

If the value can be null or undefined

Declare the nullish possibility in the type and retain optional chaining. This example allows user to be either an object or null:

user: { name: string } | null = { name: 'Angelino' };
{{ user?.name }}

If the value may instead be undefined, include that possibility in its type. The important point is that the declaration should describe the cases the application can actually produce.

If the value is guaranteed to exist

Remove the unnecessary optional chain and access the property directly:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
user: { name: string } = { name: 'Angelino' };
{{ user.name }}

Do not make a type nullable just to silence the warning if the value is in fact guaranteed to exist. Conversely, removing ?. is not appropriate if a nullish value can reach the template.

Why the warning appears

Angular extended diagnostics require strictTemplates. NG8107 also requires TypeScript strictNullChecks; without that setting, TypeScript does not enforce null and undefined checks in the same way. Angular lists NG8107 as optionalChainNotNullable among its extended diagnostics, whose default category is warning.

When the reported type seems surprising, inspect the expression’s inferred type and the declarations supplied by libraries or pipes. Angular’s template type-checking guide describes how strict template checking follows TypeScript’s null-check behavior and notes that library typings and asynchronous values can affect what the checker infers.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How to suppress NG8107

Suppression is available as a project-level escape hatch, but it hides the diagnostic rather than correcting a mismatch. Angular documents this setting under angularCompilerOptions:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
{
  "angularCompilerOptions": {
    "extendedDiagnostics": {
      "checks": {
        "optionalChainNotNullable": "suppress"
      }
    }
  }
}

Use it only when there is a deliberate reason to silence this check. First verify that the template and declared type accurately describe the value.

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 *

Free tools Windows power users keep installed

One-click scans. No signup required.

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
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver 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.