angular-docs-cn/packages/platform-browser-dynamic
Chuck Jazdzewski e7d9cb3e4c feat(compiler): narrow types of expressions used in *ngIf (#20702)
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
2017-12-08 10:24:26 -08:00
..
src feat(compiler): narrow types of expressions used in *ngIf (#20702) 2017-12-08 10:24:26 -08:00
test refactor(compiler): split compiler and core (#18683) 2017-08-16 17:58:53 -05:00
testing build: upgrade bazel rules to latest (#20768) 2017-12-07 11:27:50 -08:00
BUILD.bazel build: upgrade bazel rules to latest (#20768) 2017-12-07 11:27:50 -08:00
index.ts build: publish tree of files rather than FESMs (#18541) 2017-08-31 15:34:50 -07:00
package.json build: roll up to named .js files rather than 'index.js' (#19190) 2017-09-19 16:59:18 -07:00
public_api.ts build: publish tree of files rather than FESMs (#18541) 2017-08-31 15:34:50 -07:00
rollup.config.js refactor: make all rollup config ES5 compatible (#20028) 2017-10-30 23:09:17 -04:00
tsconfig-build.json build: remove references to `tsc-wrapped` (#19298) 2017-09-21 13:55:52 -07:00