New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(common): narrow NgIf context variables in template type checker
#36627
Conversation
|
Additionally, please change the commit scope from "ivy" to "common", as the "ivy" scope is no longer used (and will fail CI checks) |
c49d7bf
to
b1b29c6
Compare
|
@JoostK thank you for your guidance :) |
NgIf context variables in template type checkerNgIf context variables in template type checker
|
I believe I have fixed the commit message and rebased as requested. |
|
Are the "failing" checks an issue in the changes? |
|
The latter. |
|
Any news? Do I need to rebase this on a more recent master? |
|
@ranma42 - please do rebase on master - I will ping @IgorMinar to do the public API review. |
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 angular#35125
|
Is there anything I should do to make the PR process proceed? |
|
This is just awaiting other reviewers |
That's not a type AFAIK? |
|
Indeed, NaN is only a value, and using |
|
Gosh! |
|
Literal While the new typing is not yet exact, it is as narrow as possible with the current types supported by TS. |
…angular#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 angular#35125 PR Close angular#36627
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
…angular#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 angular#35125 PR Close angular#36627


When the
NgIfdirective is used in a template, its context variablescan 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:
NgIfContext.ngIfusing theassyntax:NgIfContext.$implicitusing theletsyntax:Because of the semantics of
ngIf, it is known that the capturedcontext variable is truthy, however the template type checker
would not consider them as such and still report errors when
strictis enabled.This commit updates
NgIf's context guard to make the types of thecontext variables truthy, avoiding the issue.
Based on #35125
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
When compiling in
strictmode, the compiler rejectsWhat is the new behavior?
The typing of
ngIfis more accurate, excluding most falsy values (the main exception should be NaNs) from the type passed to the template body.Does this PR introduce a breaking change?
Other information