angular-cn/packages
Alex Rickabaugh 1b4eaea6d4 feat(ivy): input type coercion for template type-checking (#33243)
Often the types of an `@Input`'s field don't fully reflect the types of
assignable values. This can happen when an input has a getter/setter pair
where the getter always returns a narrow type, and the setter coerces a
wider value down to the narrow type.

For example, you could imagine an input of the form:

```typescript
@Input() get value(): string {
  return this._value;
}

set value(v: {toString(): string}) {
  this._value = v.toString();
}
```

Here, the getter always returns a `string`, but the setter accepts any value
that can be `toString()`'d, and coerces it to a string.

Unfortunately TypeScript does not actually support this syntax, and so
Angular users are forced to type their setters as narrowly as the getters,
even though at runtime the coercion works just fine.

To support these kinds of patterns (e.g. as used by Material), this commit
adds a compiler feature called "input coercion". When a binding is made to
the 'value' input of a directive like MatInput, the compiler will look for a
static function with the name ngCoerceInput_value. If such a function is
found, the type-checking expression for the input will be wrapped in a call
to the function, allowing for the expression of a type conversion between
the binding expression and the value being written to the input's field.

To solve the case above, for example, MatInput might write:

```typescript
class MatInput {
  // rest of the directive...

  static ngCoerceInput_value(value: {toString(): string}): string {
    return null!;
  }
}
```

FW-1475 #resolve

PR Close #33243
2019-10-21 11:25:07 -04:00
..
animations feat: typescript 3.6 support (#32946) 2019-10-18 13:15:16 -04:00
bazel feat(ivy): give shim generation its own compiler options (#33256) 2019-10-21 11:24:26 -04:00
benchpress feat: update rxjs peerDependencies minimum requirment to 6.5.3 (#32812) 2019-10-01 14:56:45 -07:00
common feat: typescript 3.6 support (#32946) 2019-10-18 13:15:16 -04:00
compiler feat: typescript 3.6 support (#32946) 2019-10-18 13:15:16 -04:00
compiler-cli feat(ivy): input type coercion for template type-checking (#33243) 2019-10-21 11:25:07 -04:00
core build: fix internal Google closure issue with TS3.6 (#33257) 2019-10-18 19:48:03 -04:00
docs refactor(core): remove deprecated Renderer (#33019) 2019-10-08 09:23:00 -07:00
elements feat: typescript 3.6 support (#32946) 2019-10-18 13:15:16 -04:00
examples test: clean up explicit dynamic query usages (#33015) 2019-10-17 16:10:10 -04:00
forms feat: typescript 3.6 support (#32946) 2019-10-18 13:15:16 -04:00
http feat: typescript 3.6 support (#32946) 2019-10-18 13:15:16 -04:00
language-service refactor: format files (#31248) 2019-10-18 14:49:12 -04:00
localize build: remove vendored Babel typings (#33226) 2019-10-17 18:45:52 -04:00
platform-browser feat: typescript 3.6 support (#32946) 2019-10-18 13:15:16 -04:00
platform-browser-dynamic feat: typescript 3.6 support (#32946) 2019-10-18 13:15:16 -04:00
platform-server feat: typescript 3.6 support (#32946) 2019-10-18 13:15:16 -04:00
platform-webworker feat: typescript 3.6 support (#32946) 2019-10-18 13:15:16 -04:00
platform-webworker-dynamic feat: typescript 3.6 support (#32946) 2019-10-18 13:15:16 -04:00
private/testing test(ivy): add onlyInIvy perf counter expectations (#30339) 2019-05-09 11:22:00 -07:00
router fix(router): adjust UrlTree redirect to replace URL if in eager update (#32988) 2019-10-18 14:42:21 -04:00
service-worker feat: typescript 3.6 support (#32946) 2019-10-18 13:15:16 -04:00
upgrade feat: typescript 3.6 support (#32946) 2019-10-18 13:15:16 -04:00
zone.js build: remove vendored Babel typings (#33226) 2019-10-17 18:45:52 -04:00
BUILD.bazel refactor(core): ensure compatibility with typescript strict flag (#30993) 2019-07-18 14:21:25 -07:00
README.md
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
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 test(language-service): Create proper test project (#32653) 2019-09-18 13:07:01 -07:00
types.d.ts

README.md

Angular

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

License: MIT