Skip to content

feat(ivy): type checking of event bindings - #33125

Closed
JoostK wants to merge 2 commits into
angular:masterfrom
JoostK:ngtsc-ttc-outputs
Closed

JoostK wants to merge 2 commits into
angular:masterfrom
JoostK:ngtsc-ttc-outputs

Conversation

@JoostK

@JoostK JoostK commented Oct 12, 2019 •

Copy link
Copy Markdown
Member

Until now, the template type checker has not checked any of the event
bindings that could be present on an element, for example

<my-cmp
  (changed)="handleChange($event)"
  (click)="handleClick($event)"></my-cmp>

has two event bindings: the change event corresponding with an
@output() on the my-cmp component and the click DOM event.

This commit adds functionality to the template type checker in order to
type check both kind of event bindings. This means that the correctness
of the bindings expressions, as well as the type of the $event
variable will now be taken into account during template type checking.

Resolves FW-1598

@JoostK JoostK added feature Label used to distinguish feature request from other issues state: WIP state: blocked effort1: hours target: major This PR is targeted for the next major release comp: ivy risk: medium area: compiler Issues related to `ngc`, Angular's template compiler labels Oct 12, 2019
@ngbot ngbot Bot added this to the Backlog milestone Oct 12, 2019
@JoostK
JoostK force-pushed the ngtsc-ttc-outputs branch 2 times, most recently from f1155b2 to 922deae Compare October 12, 2019 20:03
@JoostK
JoostK force-pushed the ngtsc-ttc-outputs branch 3 times, most recently from 5edee97 to aca3790 Compare October 16, 2019 20:36
Until now, the template type checker has not checked any of the event
bindings that could be present on an element, for example

```
<my-cmp
  (changed)="handleChange($event)"
  (click)="handleClick($event)"></my-cmp>
```

has two event bindings: the `change` event corresponding with an
`@Output()` on the `my-cmp` component and the `click` DOM event.

This commit adds functionality to the template type checker in order to
type check both kind of event bindings. This means that the correctness
of the bindings expressions, as well as the type of the `$event`
variable will now be taken into account during template type checking.

Resolves FW-1598
@JoostK
JoostK force-pushed the ngtsc-ttc-outputs branch from 8bef5b4 to 3d3986c Compare October 17, 2019 18:06
@JoostK
JoostK marked this pull request as ready for review October 17, 2019 18:46
@JoostK
JoostK requested review from a team October 17, 2019 18:46
@JoostK JoostK added action: review The PR is still awaiting reviews from at least one requested reviewer and removed state: WIP labels Oct 17, 2019
return false;
} else if (code === 2695 /* Left side of comma operator is unused and has no side effects. */) {
return false;
} else if (code === 7006 /* Parameter '$event' implicitly has an 'any' type. */) {

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.

Can we make it explicit instead?
($event: any) => ...?

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.

Nope, it would defeat type inference.

@alxhub

alxhub commented Oct 18, 2019

Copy link
Copy Markdown
Member

Presubmit

@alxhub alxhub added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Oct 18, 2019
@matsko matsko closed this in 6958d11 Oct 18, 2019
@angular-automatic-lock-bot

Copy link
Copy Markdown

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.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Nov 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: compiler Issues related to `ngc`, Angular's template compiler cla: yes effort1: hours feature Label used to distinguish feature request from other issues risk: medium target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants