angular-cn/tools
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
..
brotli-cli build: Remove cc_binary dependency on brotli (#29912) 2019-04-17 17:20:16 -07:00
build build: remove obsolete files (#26471) 2018-10-23 08:57:41 -07:00
cjs-jasmine refactor(ivy): run the compiler compliance tests against ngtsc (#24862) 2018-07-20 11:48:36 -07:00
gulp-tasks Revert "feat(ivy): use i18n locale data to determine the plural form of ICU expressions (#29249)" (#29918) 2019-04-15 16:55:51 -07:00
material-ci fix(ivy): ensure parent/sub-class components evaluate styling correctly (#29602) 2019-04-05 16:49:52 -07:00
ngcontainer build: use bazel version from node modules (#26691) 2018-10-30 16:19:13 -04:00
npm style: add file header (#28871) 2019-02-28 12:06:36 -08:00
public_api_guard feat(ivy): more accurate type narrowing for `ngIf` directive (#30248) 2019-05-16 09:48:40 -07:00
rxjs 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
size-tracking build: update rules_nodejs and clean up bazel warnings (#30370) 2019-05-14 10:08:45 -07:00
source-map-test build: update npm dependencies (#19328) 2017-09-22 13:20:52 -07:00
symbol-extractor build: unable to accept new symbol-extractor golden on windows (#30127) 2019-04-26 16:35:51 -07:00
testing build(bazel): update to nodejs rules 0.27.9 (#29647) 2019-04-02 10:27:14 -07:00
ts-api-guardian refactor(ivy): migrate ɵɵ prefix back to Δ (#30362) 2019-05-14 16:52:15 -07:00
tslint build: remove unused rollup.config.js files (#28646) 2019-02-14 19:28:08 +00:00
validate-commit-message ci: remove validate-commit-message tests from travis (#27386) 2018-12-05 20:55:32 -08:00
yarn build: upgrade yarn to 1.3.2 (#21406) 2018-01-10 12:32:26 -08:00
BUILD.bazel feat(bazel): use rbe_autoconfig() and new container. (#29336) 2019-05-09 14:58:34 -07:00
bazel_stamp_vars.js build: add pre-release check that validates the version name (#29551) 2019-03-27 12:26:13 -07:00
check-environment.js build: update to Node 10 (#25822) 2018-09-06 14:58:30 -07:00
defaults.bzl fix(bazel): use //:tsconfig.json as the default for ng_module (#29670) 2019-04-02 15:57:11 -07:00
jasmine-seed-generator.js test: run unit tests in random order (#19904) 2018-07-06 13:48:02 -07:00
jsconfig.json chore(vscode): add jsconfig.json and remove .settings dir 2015-10-29 13:53:21 +00:00
postinstall-patches.js build: disable postinstall-patch.js log output (#27619) 2018-12-13 11:01:15 -08:00
rebase-pr.js ci: rebase PRs on target branch (#29215) 2019-03-12 11:34:58 -07:00
tsconfig-test.json build(bazel): use fine-grained npm deps (#26111) (#26488) 2018-10-19 20:59:29 -07:00
tsconfig.json build: ts-api-guardian tsconfig warning with bazel (#27583) 2018-12-13 11:01:48 -08:00
types.d.ts build(bazel): use bazel managed node_modules for downstream angular from source build support (#24663) 2018-07-26 17:02:21 -07:00
utils.inc feat(bundle): add script to push bundles to code.angularjs.org 2015-04-14 14:50:53 -07:00