Skip to content

feat(compiler-cli): add extended diagnostic for template reference shadowing component member#68766

Draft
arturovt wants to merge 1 commit into
angular:mainfrom
arturovt:feat/compiler_cli_shadow_45227
Draft

feat(compiler-cli): add extended diagnostic for template reference shadowing component member#68766
arturovt wants to merge 1 commit into
angular:mainfrom
arturovt:feat/compiler_cli_shadow_45227

Conversation

@arturovt
Copy link
Copy Markdown
Contributor

Adds a new extended template diagnostic (NG8119) that warns when a template reference variable (#ref) uses the same name as a public, non-static member of the component class. In those cases, the template reference silently shadows the class member within the template scope, which is usually unintended.

The diagnostic can be configured through extendedDiagnostics.checks.templateReferenceShadowsComponentVariable in the Angular compiler options.

Closes #45227

…adowing component member

Adds a new extended template diagnostic (`NG8119`) that warns when a template reference variable (`#ref`) uses the same name as a public, non-static member of the component class. In those cases, the template reference silently shadows the class member within the template scope, which is usually unintended.

The diagnostic can be configured through `extendedDiagnostics.checks.templateReferenceShadowsComponentVariable` in the Angular compiler options.

Closes angular#45227
@angular-robot angular-robot Bot added detected: feature PR contains a feature commit area: compiler Issues related to `ngc`, Angular's template compiler labels May 17, 2026
@ngbot ngbot Bot added this to the Backlog milestone May 17, 2026
@arturovt arturovt marked this pull request as ready for review May 17, 2026 16:33
@pullapprove pullapprove Bot requested a review from crisbeto May 17, 2026 16:33
@arturovt
Copy link
Copy Markdown
Contributor Author

Note: it's not a duplicate, bc it's enabled through options eliminating any breaking changes.

@JeanMeche
Copy link
Copy Markdown
Member

it's enabled through options eliminating any breaking changes.

Our template diagnostics are enabled by default. This would make this change a breaking change (and is one in G3 as our diagnostics are globally enabled there).

@JeanMeche JeanMeche marked this pull request as draft May 18, 2026 10:46
@arturovt
Copy link
Copy Markdown
Contributor Author

@JeanMeche out of curiosity, is that considered a braking change even if its a warning (not a hard error)?

@JeanMeche
Copy link
Copy Markdown
Member

Internaly, they're aren't warnings. This would require a large cleanup (likely too big to be worth it).
Or we would need to disable diagnostic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: compiler Issues related to `ngc`, Angular's template compiler breaking changes detected: feature PR contains a feature commit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

extended diagnostics: show warning if component variable is shadowed by template reference

2 participants