angular-docs-cn/packages/common/src
JoostK 40039d8068 fix(ivy): narrow `NgIf` context variables in template type checker (#35125)
When the `NgIf` directive is used in a template, its context variables
can be used to capture the bound value. This is typically used together
with a pipe or function call, 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="(user$ | async) as user">{{user.name}}</span>
```

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

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

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

Fixes #34572

PR Close #35125
2020-02-28 07:39:57 -08:00
..
directives fix(ivy): narrow `NgIf` context variables in template type checker (#35125) 2020-02-28 07:39:57 -08:00
i18n feat(common): expose getLocaleCurrencyCode publicly (#34810) 2020-01-23 13:18:53 -08:00
location perf(core): Make `PlatformLocation` tree-shakable (#32154) 2019-08-29 21:51:56 -07:00
pipes docs: add deprecation info about default currency code (#32584) 2020-01-13 09:57:06 -08:00
common.ts Revert: "feat(ivy): convert [ngStyle] and [ngClass] to use ivy styling bindings" (#34616) 2020-01-24 12:22:44 -08:00
common_module.ts fix(common): remove deprecated support for intl API (#29250) 2019-10-17 20:44:17 -04:00
cookie.ts feat(common): on-by-default XSRF support in HttpClient (#18108) 2017-07-13 17:22:02 -07:00
dom_adapter.ts refactor(core): move Meta methods that only have one version from DomAdapter (#32408) 2019-09-03 11:59:39 -07:00
dom_tokens.ts docs(common): Fixes typo (#33003) 2019-10-10 13:55:40 -07:00
platform_id.ts docs: convert all `@experimental` tags to `@publicApi` tags (#26595) 2018-10-19 14:35:52 -07:00
private_export.ts build: remove unneeded style code for ngClass and ngStyle (#34998) 2020-01-29 14:57:21 -08:00
version.ts docs: common with `@publicApi` tags (#26595) 2018-10-19 14:35:53 -07:00
viewport_scroller.ts refactor(core): rename ngInjectableDef to ɵprov (#33151) 2019-10-16 16:36:19 -04:00