Repository navigation
feat(compiler): allow ngIf to use the ngIf expression directly as a guard - #20972
Merged
Merged
Conversation
|
You can preview bd6bacc at https://pr20972-bd6bacc.ngbuilds.io/. |
…uard Allows a directive to use the expression passed directly to a property as a guard instead of filtering the type through a type expression. This more accurately matches the intent of the ngIf usage of its template enabling better type inference. Moved NgIf to using this type of guard instead of a function guard. Closes: angular#20967
|
You can preview c97ce64 at https://pr20972-c97ce64.ngbuilds.io/. |
vicb
approved these changes
Dec 13, 2017
mhevery
approved these changes
Dec 14, 2017
Member
|
PullApprove broken, Misko approved. |
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Allows a directive to use the expression passed directly to a property
as a guard instead of filtering the type through a type guard function.
This more accurately matches the intent of the ngIf usage of its template
enabling better type inference.
Moved NgIf to using this type of guard instead of a function guard.
Closes: #20967
PR Type
What kind of change does this PR introduce?
What is the current behavior?
#20967
Using the type guard mechanism introduced in e7d9cb3 the following expression is not narrowed as expected.
because the type guard function only infers that the expression
!!personis true but does not further infer that implies person is notundefinedcausingperson.nameto report thatpersonmight beundefined.What is the new behavior?
The code generated for an
*ngIfuses the guard expression directly as the template guard instead of using a type guard function. This allows TypeScript to infer the correct types forpersonin the above example.Does this PR introduce a breaking change?