Skip to content

fix(compiler-cli): detect uninvoked signals in bound expressions using ternary#68079

Open
cexbrayat wants to merge 1 commit intoangular:mainfrom
cexbrayat:fix/interpolated-signal-bound-expr
Open

fix(compiler-cli): detect uninvoked signals in bound expressions using ternary#68079
cexbrayat wants to merge 1 commit intoangular:mainfrom
cexbrayat:fix/interpolated-signal-bound-expr

Conversation

@cexbrayat
Copy link
Copy Markdown
Member

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.dev application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

The current diagnostic does not report the uninvoked signal in the following case:

<div [style.width]="width() ? 1 : width"></div>

where the false branch should invoke the signal as width().

What is the new behavior?

Extend the interpolated signal extended diagnostic to inspect ternary-bound expressions.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Also added tests to cover already handled cases

…g ternary

Extend the interpolated signal extended diagnostic to inspect ternary-bound expressions and report uninvoked signal reads in bound bindings.

```
<div [style.width]="width() ? 1 : width"></div>
```

where the false branch should invoke the signal as `width()`.
@pullapprove pullapprove bot requested a review from kirjs April 8, 2026 11:08
@angular-robot angular-robot bot added the area: compiler Issues related to `ngc`, Angular's template compiler label Apr 8, 2026
@JeanMeche JeanMeche added the requires: TGP This PR requires a passing TGP before merging is allowed label Apr 8, 2026
@ngbot ngbot bot added this to the Backlog milestone Apr 8, 2026
@JeanMeche JeanMeche requested review from JeanMeche and removed request for kirjs April 8, 2026 11:12
@JeanMeche
Copy link
Copy Markdown
Member

Passing TGP

{
fileName,
templates: {
'TestCmp': `<div [style.width]="width() ? 1 : width"></div>`,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be picked up by the typechecker ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think the type-checker can catch this, because checkTypeOfDomBindings is currently always false (even with strictTemplates)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah but is it a reason to fix it here ?
This diagnostic should only address cases where the type system cannot see the problem.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is, as we don't have a compiler that checks dom bindings (and we'll maybe never have one?). Even if it was, the error message would not be as precise as the one coming from the diagnostic.

This is a real issue we encountered in a migrated app, so I thought it would be worth it to spare the pain to other developers.

@JeanMeche JeanMeche added action: merge The PR is ready for merge by the caretaker and removed action: merge The PR is ready for merge by the caretaker labels Apr 11, 2026
{
fileName,
templates: {
'TestCmp': `<div [style.width]="width() ? 1 : width"></div>`,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah but is it a reason to fix it here ?
This diagnostic should only address cases where the type system cannot see the problem.

{
fileName,
templates: {
'TestCmp': `<button [disabled]="!isEnabled"></button>`,
Copy link
Copy Markdown
Member

@JeanMeche JeanMeche Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one seems a good case for the diagnostic to cover !

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 requires: TGP This PR requires a passing TGP before merging is allowed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants