angular/packages
JoostK e9ead2bc09 feat(ivy): more accurate type narrowing for ngIf directive (#30248)
A structural directive can specify a template guard for an input, such that
the type of that input's binding can be narrowed based on the guard's return
type. Previously, such template guards could only be methods, of which an
invocation would be inserted into the type-check block (TCB). For `NgIf`,
the template guard narrowed the type of its expression to be `NonNullable`
using the following declaration:

```typescript
export declare class NgIf {
  static ngTemplateGuard_ngIf<E>(dir: NgIf, expr: E): expr is NonNullable<E>
}
```

This works fine for usages such as `*ngIf="person"` but starts to introduce
false-positives when e.g. an explicit non-null check like
`*ngIf="person !== null"` is used, as the method invocation in the TCB
would not have the desired effect of narrowing `person` to become
non-nullable:

```typescript
if (NgIf.ngTemplateGuard_ngIf(directive, ctx.person !== null)) {
  // Usages of `ctx.person` within this block would
  // not have been narrowed to be non-nullable.
}
```

This commit introduces a new strategy for template guards to allow for the
binding expression itself to be used as template guard in the TCB. Now,
the TCB generated for `*ngIf="person !== null"` would look as follows:

```typescript
if (ctx.person !== null) {
  // This time `ctx.person` will successfully have
  // been narrowed to be non-nullable.
}
```

This strategy can be activated by declaring the template guard as a
property declaration with `'binding'` as literal return type.

See #30235 for an example where this led to a false positive.

PR Close #30248
2019-05-16 09:48:40 -07:00
..
animations docs(animations): fixed some closing brackets on query animation page (#29854) (#29855) 2019-04-18 18:19:48 -07:00
bazel fix(bazel): Disable sandbox on Mac OS (#30460) 2019-05-16 09:43:54 -07:00
benchpress build: update rxjs version requirements to 6.4.0 (#30032) 2019-04-22 11:15:33 -07:00
common feat(ivy): more accurate type narrowing for ngIf directive (#30248) 2019-05-16 09:48:40 -07:00
compiler test: fix compiler tests in windows ci (#30482) 2019-05-16 09:43:01 -07:00
compiler-cli feat(ivy): more accurate type narrowing for ngIf directive (#30248) 2019-05-16 09:48:40 -07:00
core fix(ivy): do not throw if host style is on a template node (#30498) 2019-05-16 09:42:34 -07:00
docs refactor: move angular source to /packages rather than modules/@angular 2017-03-08 16:29:27 -08:00
elements build: update rxjs version requirements to 6.4.0 (#30032) 2019-04-22 11:15:33 -07:00
examples docs(forms): properly convert number to string for formControlName input (#29473) 2019-05-09 11:27:48 -07:00
forms docs(forms): add comment of the value (#29898) 2019-05-09 11:25:58 -07:00
http build: update rxjs version requirements to 6.4.0 (#30032) 2019-04-22 11:15:33 -07:00
language-service build: update rules_nodejs and clean up bazel warnings (#30370) 2019-05-14 10:08:45 -07:00
platform-browser refactor(ivy): migrate ɵɵ prefix back to Δ (#30362) 2019-05-14 16:52:15 -07:00
platform-browser-dynamic refactor(ivy): prefix all generated instructions (#29692) 2019-04-10 12:11:40 -07:00
platform-server feat(common): add @angular/common/upgrade package for $location-related APIs (#30055) 2019-04-24 13:49:29 -07:00
platform-webworker feat(common): add @angular/common/upgrade package for $location-related APIs (#30055) 2019-04-24 13:49:29 -07:00
platform-webworker-dynamic build: remove now redundant bundle_dts = True attribute (#29128) 2019-03-07 10:47:20 -08:00
private/testing test(ivy): add onlyInIvy perf counter expectations (#30339) 2019-05-09 11:22:00 -07:00
router fix(router): type cast correctly for IE 11 bug breaking URL Unification when comparing objects (#30464) 2019-05-15 14:09:53 -07:00
service-worker feat(service-worker): support bypassing SW with specific header/query param (#30010) 2019-04-25 13:09:44 -07:00
upgrade test(upgrade): rename angular.module() to angular.module_() (#30126) 2019-04-25 12:01:18 -07:00
BUILD.bazel build: rules_nodejs 0.26.0 & use @npm instead of @ngdeps now that downstream angular build uses angular bundles (#28871) 2019-02-28 12:06:36 -08:00
empty.ts refactor: move angular source to /packages rather than modules/@angular 2017-03-08 16:29:27 -08:00
goog.d.ts test(ivy): add bundling test todo_i18n (#27420) 2018-12-04 19:59:12 -08:00
license-banner.txt build: bump year (#27880) 2019-01-11 11:15:59 -08:00
README.md Revert "docs: Remove unneeded file (#18106)" 2017-07-20 16:46:47 -05:00
system.d.ts refactor: move angular source to /packages rather than modules/@angular 2017-03-08 16:29:27 -08:00
tsconfig-build.json build: update to rules_typescript 0.25.1 (#28625) 2019-02-21 07:46:21 -08:00
tsconfig-test.json build: update to rules_typescript 0.25.1 (#28625) 2019-02-21 07:46:21 -08:00
tsconfig.json docs(service-worker): improve SwRegistrationOptions docs and add example (#21842) 2019-04-25 12:29:58 -07:00
types.d.ts build: switch to typescript's es2015 typings (#28570) 2019-02-06 14:17:55 -05:00

Angular

The sources for this package are in the main Angular repo. Please file issues and pull requests against that repo.

License: MIT