mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
Structural directives can now specify a type guard that describes
what types can be inferred for an input expression inside the
directive's template.
NgIf was modified to declare an input guard on ngIf.
After this change, `fullTemplateTypeCheck` will infer that
usage of `ngIf` expression inside it's template is truthy.
For example, if a component has a property `person?: Person`
and a template of `<div *ngIf="person"> {{person.name}} </div>`
the compiler will no longer report that `person` might be null or
undefined.
The template compiler will generate code similar to,
```
if (NgIf.ngIfTypeGuard(instance.person)) {
instance.person.name
}
```
to validate the template's use of the interpolation expression.
Calling the type guard in this fashion allows TypeScript to infer
that `person` is non-null.
Fixes: #19756?
PR Close #20702
|
||
|---|---|---|
| .. | ||
| build | ||
| cjs-jasmine | ||
| code.angularjs.org | ||
| gulp-tasks | ||
| karma | ||
| npm | ||
| public_api_guard | ||
| source-map-test | ||
| travis | ||
| tree-shaking-test | ||
| tsc-watch | ||
| tslint | ||
| validate-commit-message | ||
| bazel.rc | ||
| check-environment.js | ||
| chromedriverpatch.js | ||
| jsconfig.json | ||
| tsconfig.json | ||
| types.d.ts | ||
| utils.inc | ||