Repository navigation
Closed
Labels
area: compilerIssues related to `ngc`, Angular's template compilercompiler: template type-checkingstate: confirmed
Milestone
Description
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
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
Labels
area: compilerIssues related to `ngc`, Angular's template compilercompiler: template type-checkingstate: confirmed
Activity
JeanMeche commentedon Aug 5, 2026
Looks we are adding some parenthesis in the TCB which changing the semantics.
robertIsaac commentedon Aug 5, 2026
@JeanMeche I dig deeper into the
strict: trueit seems that default now should be true according to announcing typescript 6but in the provided repo if you removed it then the warning is removed
it seems that angular compiler doesn't respect the new strict default value
this was the most confusing part for me, because when I tried to reproduce the error in a new project it wasn't showing and took me a while to see that the only different was
strict: truein the real project vs none in the reprod oneAyushDubey23 commentedon Aug 5, 2026
Thanks for the report! As @JeanMeche pointed out, the generated TCB's
for...ofloop applied a trailing!, causing TypeScript to incorrectly narrow intermediate safe-navigation receivers and triggering false NG8107 warnings.This is fixed by emitting the original expression before the
for...ofloop, preserving the correct nullable types for extended diagnostics.JeanMeche commentedon Aug 5, 2026
@robertIsaac This is actually an interesting feedback and worth of a distinct issue: Our diagnostics seems to only report this issue (and probably others) when the option is explicitly set to true.
JeanMeche commentedon Aug 5, 2026
#70090 would address the strictness issue.
robertIsaac commentedon Aug 5, 2026
I'm very happy to hear that my investigation helped to pinpoint two issues
Thanks @JeanMeche for the quick fixes
fix(compiler): Generate correct expression for optional chaning.
fix(compiler): Generate correct expression for optional chaning.
angular-automatic-lock-bot commentedon Oct 19, 2026
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.