Skip to content

false positive for NG8107 when used inside @for #70085

Description

@robertIsaac

Which @angular/* package(s) are the source of the bug?

compiler

Is this a regression?

Yes

Description

right now after the migration to angular 22 we are getting a lot of warnings for a false positive of NG8107 error when used inside a template @for when strict is enabled (I don't understand why in angular 22 by default it's not enabled)

Please provide a link to a minimal reproduction of the bug

https://github.com/robertIsaac/optional-chain-angular-reprod

Please provide the exception or error you saw

▲ [WARNING] NG8107: NG8107: The left side of this optional chain operation does not include 'null' or 'undefined' in its type, therefore the '?.' operator can be replaced with the '.' operator. Find more at https://v22.angular.dev/extended-diagnostics/NG8107 [plugin angular-compiler]

    src/app/app.html:1:38:
      1 │ @for (item of type().one?.two?.three?.array; track item.name) {
        ╵                                       ~~~~~

  Warning occurs in the template of component App.

    src/app/app.ts:17:15:
      17 │   templateUrl: './app.html',
         ╵                ~~~~~~~~~~~~


▲ [WARNING] NG8107: NG8107: The left side of this optional chain operation does not include 'null' or 'undefined' in its type, therefore the '?.' operator can be replaced with the '.' operator. Find more at https://v22.angular.dev/extended-diagnostics/NG8107 [plugin angular-compiler]

    src/app/app.html:1:38:
      1 │ @for (item of type().one?.two?.three?.array; track item.name) {
        ╵                                       ~~~~~

  Warning occurs in the template of component App.

    src/app/app.ts:17:15:
      17 │   templateUrl: './app.html',
         ╵                ~~~~~~~~~~~~

Please provide the environment you discovered this bug in (run ng version)

ngular CLI       : 22.1.3
Angular           : 22.1.0
Node.js           : 24.15.0
Package Manager   : npm 11.17.0
Operating System  : darwin arm64

┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package                   │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build            │ 22.1.3            │ ^22.1.3           │
│ @angular/cli              │ 22.1.3            │ ^22.1.3           │
│ @angular/common           │ 22.1.0            │ ^22.1.0           │
│ @angular/compiler         │ 22.1.0            │ ^22.1.0           │
│ @angular/compiler-cli     │ 22.1.0            │ ^22.1.0           │
│ @angular/core             │ 22.1.0            │ ^22.1.0           │
│ @angular/forms            │ 22.1.0            │ ^22.1.0           │
│ @angular/platform-browser │ 22.1.0            │ ^22.1.0           │
│ @angular/router           │ 22.1.0            │ ^22.1.0           │
│ rxjs                      │ 7.8.2             │ ~7.8.0            │
│ typescript                │ 6.0.3             │ ~6.0.2            │
│ vitest                    │ 4.1.10            │ ^4.0.8            │
└───────────────────────────┴───────────────────┴───────────────────┘

Anything else?

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions