angular-cn/packages/compiler-cli/test/ngtsc
Alex Rickabaugh eb6975acaf fix(ivy): don't infer template context types when in full mode (#33537)
The Ivy template type-checker is capable of inferring the type of a
structural directive (such as NgForOf<T>). Previously, this was done with
fullTemplateTypeCheck: true, even if strictTemplates was false. View Engine
previously did not do this inference, and so this causes breakages if the
type of the template context is not what the user expected.

In particular, consider the template:

```html
<div *ngFor="let user of users as all">
  {{user.index}} out of {{all.length}}
</div>
```

As long as `users` is an array, this seems reasonable, because it appears
that `all` is an alias for the `users` array. However, this is misleading.

In reality, `NgForOf` is rendered with a template context that contains
both a `$implicit` value (for the loop variable `user`) as well as a
`ngForOf` value, which is the actual value assigned to `all`. The type of
`NgForOf`'s template context is `NgForContext<T>`, which declares `ngForOf`'s
type to be `NgIterable<T>`, which does not have a `length` property (due to
its incorporation of the `Iterable` type).

This commit stops the template type-checker from inferring template context
types unless strictTemplates is set (and strictInputTypes is not disabled).

Fixes #33527.

PR Close #33537
2019-11-20 11:47:42 -08:00
..
fake_core fix(core): make QueryList implement Iterable in the type system (#33536) 2019-11-19 13:43:53 -08:00
BUILD.bazel build: remove redundant `@types/source-map` dependency (#31468) 2019-07-11 17:18:12 -04:00
component_indexing_spec.ts feat(ivy): index template references, variables, bound attributes/events (#31535) 2019-07-25 13:09:10 -07:00
env.ts test(ivy): driveDiagnostics() works incrementally (#33862) 2019-11-20 11:46:02 -08:00
incremental_error_spec.ts fix(ivy): always re-analyze the program during incremental rebuilds (#33862) 2019-11-20 11:46:02 -08:00
incremental_spec.ts fix(ivy): ensure module scope is rebuild on dependent change (#33522) 2019-11-12 13:56:30 -08:00
monorepo_spec.ts fix(ivy): emit fs-relative paths when rootDir(s) aren't in effect (#33828) 2019-11-19 12:41:24 -08:00
ngtsc_spec.ts refactor(compiler-cli): avoid superfluous parenthesis around statements (#33514) 2019-11-13 13:49:30 -08:00
scope_spec.ts refactor(core): rename ngModuleDef to ɵmod (#33142) 2019-10-14 23:08:10 +00:00
sourcemap_utils.ts refactor(ivy): implement a virtual file-system layer in ngtsc + ngcc (#30921) 2019-06-25 16:25:24 -07:00
template_mapping_spec.ts perf(ivy): move attributes array into component def (#32798) 2019-10-09 13:16:55 -07:00
template_typecheck_spec.ts fix(ivy): don't infer template context types when in full mode (#33537) 2019-11-20 11:47:42 -08:00