-
Notifications
You must be signed in to change notification settings - Fork 25.3k
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
Decide how to reconcile async
pipe with strict template type checking
#33704
Comments
Thank you for clarifying the problem. As a user, even if not Ivy, this has been a long-standing issue and very tough. I think it isn't the child component's responsibility to be prepared for the possibility of null. The trouble is that even if it is non-nullable, the value is not always available. It can delay. |
Wouldn't it have to be the other way around, introduce the new behavior as asyncLazy, to not make a breaking change? Unless you intend to write a migration that changes all occurrences, but you'd also have to replace programmatic usages of the pipe. Alternatively don't create a whole separate pipe but just make it accept a parameter for the initial value:
For simple type inputs a migration could be written that adds the respective default value of that type (boolean => false etc.) as the initial value. This is at least very likely to do the correct thing; if it wouldn't, the component would have a broken API because it should actually declare to expect null. |
@Airblader yeah I was thinking create a schematic to rename it, since we'd want to keep the |
we discussed this today, and we agreed that to fix this properly, we should look at typing of inputs in general and properly allow inputs to be optional, required, etc. for v9 the best we can likely do is that for users that want to use This should be explicitly documented in the v9 updating guide or template type checking guide. |
The docs changes have landed. Is there anything else required for this or can we close the issue @alxhub |
I consider this resolved. With the way Angular works today, at runtime the |
@IgorMinar is this tracked in an existing issue on GitHub or Jira? |
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. |
🚀 feature request
Relevant Package
This feature request is for @angular/common
Description
Currently the
async
pipe is difficult to use withstrictTemplates
andstrictNullChecks
enabled. This is because theasync
pipe emitsnull
if the underlying observable has not emitted yet. Therefore using theasync
pipe with an input that does not acceptnull
will result in a compilation error.@devversion has done a more detailed write-up of this issue. I'm including a summary of the possible solutions here, but please refer to the write-up for more details.
Describe the solution you'd like
The ideal solution would be to make
async
pipe not emit until the underlying observable emits, however this would likely be a fairly breaking change. It would probably need to be done in a phased manner, while introducing something likeasyncEager
that maintains the old behavior to make migration easier.Describe alternatives you've considered
An option that would split the responsibility for fixing between framework and libraries is to introduce something like
@RequiredInput(fallbackValue)
that automatically replacesnull
withfallbackValue
. Libraries could then update their inputs to use@RequiredInput
whennull
is not expected.Another option that would place the responsibility on libraries is to ask them to just handle
null
and allow it to be passed in the template even if its not part of the input's official type (usingstatic ngAcceptInputType_*
)Finally, a third alternative is to just pass the responsibility down to the app developer to fill in a default:
[someInput]="(value$ | async) || defaultValue"
The text was updated successfully, but these errors were encountered: