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

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

PR Close #33125
This commit is contained in:
JoostK
2019-10-12 18:38:47 +02:00
committed by Matias Niemelä
parent bfd07b3c94
commit 6958d11d95
15 changed files with 787 additions and 130 deletions

View File

@ -405,6 +405,13 @@ export class NgtscProgram implements api.Program {
strictNullInputBindings: true,
// Even in full template type-checking mode, DOM binding checks are not quite ready yet.
checkTypeOfDomBindings: false,
checkTypeOfOutputEvents: true,
checkTypeOfAnimationEvents: true,
// Checking of DOM events currently has an adverse effect on developer experience,
// e.g. for `<input (blur)="update($event.target.value)">` enabling this check results in:
// - error TS2531: Object is possibly 'null'.
// - error TS2339: Property 'value' does not exist on type 'EventTarget'.
checkTypeOfDomEvents: false,
checkTypeOfPipes: true,
strictSafeNavigationTypes: true,
};
@ -416,6 +423,9 @@ export class NgtscProgram implements api.Program {
checkTypeOfInputBindings: false,
strictNullInputBindings: false,
checkTypeOfDomBindings: false,
checkTypeOfOutputEvents: false,
checkTypeOfAnimationEvents: false,
checkTypeOfDomEvents: false,
checkTypeOfPipes: false,
strictSafeNavigationTypes: false,
};