angular-docs-cn/packages
Alex Rickabaugh 173a1ac8e4 fix(ivy): better inference for circularly referenced directive types (#35622)
It's possible to pass a directive as an input to itself. Consider:

```html
<some-cmp #ref [value]="ref">
```

Since the template type-checker attempts to infer a type for `<some-cmp>`
using the values of its inputs, this creates a circular reference where the
type of the `value` input is used in its own inference:

```typescript
var _t0 = SomeCmp.ngTypeCtor({value: _t0});
```

Obviously, this doesn't work. To resolve this, the template type-checker
used to generate a `null!` expression when a reference would otherwise be
circular:

```typescript
var _t0 = SomeCmp.ngTypeCtor({value: null!});
```

This effectively asks TypeScript to infer a value for this context, and
works well to resolve this simple cycle. However, if the template
instead tries to use the circular value in a larger expression:

```html
<some-cmp #ref [value]="ref.prop">
```

The checker would generate:

```typescript
var _t0 = SomeCmp.ngTypeCtor({value: (null!).prop});
```

In this case, TypeScript can't figure out any way `null!` could have a
`prop` key, and so it infers `never` as the type. `(never).prop` is thus a
type error.

This commit implements a better fallback pattern for circular references to
directive types like this. Instead of generating a `null!` in place for the
reference, a type is inferred by calling the type constructor again with
`null!` as its input. This infers the widest possible type for the directive
which is then used to break the cycle:

```typescript
var _t0 = SomeCmp.ngTypeCtor(null!);
var _t1 = SomeCmp.ngTypeCtor({value: _t0.prop});
```

This has the desired effect of validating that `.prop` is legal for the
directive type (the type of `#ref`) while also avoiding a cycle.

Fixes #35372
Fixes #35603
Fixes #35522

PR Close #35622
2020-02-26 12:57:08 -08:00
..
animations build(packaging): add repository.directory field to package.jsons (#27544) 2020-02-25 13:12:45 -08:00
bazel build(packaging): add repository.directory field to package.jsons (#27544) 2020-02-25 13:12:45 -08:00
benchpress build(packaging): add repository.directory field to package.jsons (#27544) 2020-02-25 13:12:45 -08:00
common docs(common): update ngForTrackBy error URL (#34761) 2020-02-26 12:47:48 -08:00
compiler build(packaging): add repository.directory field to package.jsons (#27544) 2020-02-25 13:12:45 -08:00
compiler-cli fix(ivy): better inference for circularly referenced directive types (#35622) 2020-02-26 12:57:08 -08:00
core fix(core): support sanitizer value in the [style] bindings (#35564) 2020-02-26 12:56:09 -08:00
docs refactor(core): remove deprecated Renderer (#33019) 2019-10-08 09:23:00 -07:00
elements build(packaging): add repository.directory field to package.jsons (#27544) 2020-02-25 13:12:45 -08:00
examples docs: changes AoT to AOT for consistency (#35112) 2020-02-04 10:43:33 -08:00
forms build(packaging): add repository.directory field to package.jsons (#27544) 2020-02-25 13:12:45 -08:00
http build(packaging): add repository.directory field to package.jsons (#27544) 2020-02-25 13:12:45 -08:00
language-service build(packaging): add repository.directory field to package.jsons (#27544) 2020-02-25 13:12:45 -08:00
localize fix(localize): improve placeholder mismatch error message (#35593) 2020-02-24 09:11:21 -08:00
platform-browser build(packaging): add repository.directory field to package.jsons (#27544) 2020-02-25 13:12:45 -08:00
platform-browser-dynamic build(packaging): add repository.directory field to package.jsons (#27544) 2020-02-25 13:12:45 -08:00
platform-server build(packaging): add repository.directory field to package.jsons (#27544) 2020-02-25 13:12:45 -08:00
platform-webworker build(packaging): add repository.directory field to package.jsons (#27544) 2020-02-25 13:12:45 -08:00
platform-webworker-dynamic build(packaging): add repository.directory field to package.jsons (#27544) 2020-02-25 13:12:45 -08:00
private/testing build: migrate determining if Ivy is enabled in typescript genrule files to use angular_ivy_enabled (#33983) 2019-11-26 16:38:40 -05:00
router build(packaging): add repository.directory field to package.jsons (#27544) 2020-02-25 13:12:45 -08:00
service-worker build(packaging): add repository.directory field to package.jsons (#27544) 2020-02-25 13:12:45 -08:00
upgrade build(packaging): add repository.directory field to package.jsons (#27544) 2020-02-25 13:12:45 -08:00
zone.js feat: add interface definitions which zone extends EventTarget (#35304) 2020-02-26 12:52:08 -08:00
BUILD.bazel build: reference zone.js from source directly instead of npm. (#33046) 2019-11-06 00:48:34 +00:00
README.md docs: add doc reference to npm package readme (#33911) 2019-11-20 14:46:23 -08:00
empty.ts
goog.d.ts fix(ivy): use goog.LOCALE for Closure Compiler to define default LOCALE_ID (#31519) 2019-07-16 13:02:10 -04:00
license-banner.txt build: bump year (#34651) 2020-01-13 07:21:43 -08:00
system.d.ts
tsconfig-build-no-strict.json refactor(core): ensure compatibility with typescript strict flag (#30993) 2019-07-18 14:21:25 -07:00
tsconfig-build.json refactor(core): ensure compatibility with typescript strict flag (#30993) 2019-07-18 14:21:25 -07:00
tsconfig-test.json refactor: fix typescript strict flag failures in all tests (#30993) 2019-07-18 14:21:26 -07:00
tsconfig.json build: consolidate @angular-devkit/build-angular to the root package.json (#34002) 2019-12-02 10:49:12 -08:00
types.d.ts build: reference zone.js from source directly instead of npm. (#33046) 2019-11-06 00:48:34 +00:00

README.md

Angular

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

Usage information and reference details can be found in Angular documentation.

License: MIT