Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Change async pipe's default value from null to undefined #39785
Conversation
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
2ecf20d
to
e3b0aa5
|
You are correct that Could you get the tests green? Once the tests are green we can try to see what it would take to land it in Google codebase, but I suspect it will not be trivial. |
|
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the |
It is an incorrect approach to return `null` when the actual value is unknown. The convention is to use `undefined` for a variable that has not yet been assigned a value, whereas `null` is an assignment value and represents no value. BREAKING CHANGE: The async pipe now returns `undefined` as the default value. Requires a fix when relying on the async pipe returning `null` as the default value. Fixes #16982
42a8dd7
to
5397cc9
Changes async pipe's default value from
nulltoundefined. It is an incorrect approach to returnnullwhen the actual value is unknown. The convention is to useundefinedfor a variable that has not yet been assigned a value, whereasnullis an assignment value and represents no value (more details for example on Stack Overflow).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?
Angular's async pipe subscribes to Observables and Promises and returns the latest value. But when there is no value yet, it returns
null. This can lead to some unexpected issues, for example imagine a component with an input like this:The component can then be used in a template without any problems like this (where myNumber is type of
number):But when myNumber would be of type
Observable<number>and we'd like to use it with the async pipe, it would lead tonullbeing passed to the number component instead ofundefined:A typical use case for this is firing an async HTTP request, displaying some loading element for value of
undefined, a value for the actual value, and anything else ("no data", error, ...) fornull. The current async pipe breaks this pattern and can cause a headache finding what went wrong as this is not the expected behavior.Issue Number: #16982
What is the new behavior?
The async pipe now returns
undefinedby default before an actual value is emitted. It still returnsnullfor inputs of typenullandundefinedto keep it consistent with other pipes (PR #37447).This PR follows @mhevery's comment to see how breaking it is. As discussed in the issue #16982, it is not fully clear whether this should be a fix or a feature.
Does this PR introduce a breaking change?
The async pipe now returns
undefinedas the default value. Requires a fix if you performed a check for thenullvalue before, but this check was likely needed solely because of this unconventional behavior.Other information
I've also updated the doc comment that this pipe returns
undefinedbefore the first emit, as I was lacking this information aboutnullthere before.