angular/packages/compiler-cli/test/ngtsc
Andrea Canciani 9c8bc4a239 fix(common): narrow NgIf context variables in template type checker (#36627)
When the `NgIf` directive is used in a template, its context variables
can be used to capture the bound value. This is sometimes used in
complex expressions, where the resulting value is captured in a
context variable. There's two syntax forms available:

1. Binding to `NgIfContext.ngIf` using the `as` syntax:
```html
<span *ngIf="enabled && user as u">{{u.name}}</span>
```

2. Binding to `NgIfContext.$implicit` using the `let` syntax:
```html
<span *ngIf="enabled && user; let u">{{u.name}}</span>
```

Because of the semantics of `ngIf`, it is known that the captured
context variable is truthy, however the template type checker
would not consider them as such and still report errors when
`strict` is enabled.

This commit updates `NgIf`'s context guard to make the types of the
context variables truthy, avoiding the issue.

Based on https://github.com/angular/angular/pull/35125

PR Close #36627
2020-07-29 10:30:44 -07:00
..
fake_core build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
BUILD.bazel perf(compiler-cli): fix regressions in incremental program reuse (#37641) 2020-06-25 14:12:20 -07:00
component_indexing_spec.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
env.ts fix(compiler-cli): ensure file_system handles mixed Windows drives (#37959) 2020-07-13 12:05:21 -07:00
incremental_error_spec.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
incremental_spec.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
modulewithproviders_spec.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
monorepo_spec.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
ngtsc_spec.ts fix(compiler): share identical stylesheets between components in the same file (#38213) 2020-07-27 10:04:30 -07:00
scope_spec.ts feat(compiler-cli): explain why an expression cannot be used in AOT compilations (#37587) 2020-06-25 14:16:35 -07:00
sourcemap_utils.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
template_mapping_spec.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
template_typecheck_spec.ts fix(common): narrow NgIf context variables in template type checker (#36627) 2020-07-29 10:30:44 -07:00