angular-cn/packages/compiler-cli/test
JoostK 7525f3afc1 fix(compiler-cli): type-check inputs that include undefined when there's coercion members (#38273)
For attribute bindings that target a directive's input, the template
type checker is able to verify that the type of the input expression is
compatible with the directive's declaration for said input. This
checking adheres to the `strictNullChecks` flag as configured in the
TypeScript compilation, such that errors are reported for expressions
that include `undefined` or `null` in their type if the input's
declaration does not include those types.

There was a bug with this level of type-checking for directives that
also declare coercion members, where binding an expression that includes
the `undefined` type to a directive's input that does not include the
`undefined` type would not be reported as error.

This commit fixes the bug by changing the type-constructor in type-check
code to use an intersection type of regular inputs and coerced inputs,
instead of a union type. The union type would inadvertently allow
`undefined` types to be assigned into the regular inputs, as that would
still satisfy the characteristics of a union type.

As a result of this change, you may start to see build failures if
`strictTemplates` is enabled and `strictInputTypes` is not disabled.
These errors are legitimate and some action is required to achieve a
successful build:

1. Update the templates for which an error is reported and introduce the
   non-null assertion operator at the end of the expression. This
   removes the `undefined` type from the expression's type, making it
   appear as a valid assignment.
2. Disable `strictNullInputTypes` in the compiler options. This will
   implicitly add the non-null assertion operators similar to option 1,
   but all templates in the compilation are affected.
3. Update the directive's input declaration to include the `undefined`
   type, if the directive is not implemented in an external library.

PR Close #38273
2020-08-06 15:21:02 -07:00
..
compliance refactor(core): rename synthetic host property and listener instructions (#37145) 2020-07-21 09:09:24 -07:00
diagnostics build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
helpers fix(ngcc): correctly get config for sub-entry-points when primary entry-point is ignored (#37040) 2020-06-11 18:58:36 -07:00
metadata build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
ngtsc fix(compiler-cli): type-check inputs that include undefined when there's coercion members (#38273) 2020-08-06 15:21:02 -07:00
transformers refactor(compiler-cli): skip class decorators in tooling constructor parameters transform (#37545) 2020-06-15 12:47:57 -07:00
BUILD.bazel build: derive ts_library dep from jasmine_node_test boostrap label if it ends in `_es5` (#34736) 2020-01-15 14:58:07 -05:00
extract_i18n_spec.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
mocks.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
ngc_spec.ts fix(compiler-cli): downlevel angular decorators to static properties (#37382) 2020-06-10 09:24:11 -07:00
perform_compile_spec.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
perform_watch_spec.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
test_support.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
typescript_support_spec.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00