question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Decide how to reconcile `async` pipe with strict template type checking

See original GitHub issue

🚀 feature request

Relevant Package

This feature request is for @angular/common

Description

Currently the async pipe is difficult to use with strictTemplates and strictNullChecks enabled. This is because the async pipe emits null if the underlying observable has not emitted yet. Therefore using the async pipe with an input that does not accept null 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 like asyncEager that maintains the old behavior to make migration easier.

Describe alternatives you’ve considered

  1. An option that would split the responsibility for fixing between framework and libraries is to introduce something like @RequiredInput(fallbackValue) that automatically replaces null with fallbackValue. Libraries could then update their inputs to use @RequiredInput when null is not expected.

  2. 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 (using static ngAcceptInputType_*)

  3. Finally, a third alternative is to just pass the responsibility down to the app developer to fill in a default: [someInput]="(value$ | async) || defaultValue"

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:8
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

8reactions
IgorMinarcommented, Nov 11, 2019

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 strictTemplates and strictNullChecks together, they can opt out of strict null typecheck specifically for input bindings via strictNullInputTypes : https://v9.angular.io/guide/template-typecheck#troubleshooting-template-errors

This should be explicitly documented in the v9 updating guide or template type checking guide.

2reactions
alxhubcommented, Jan 23, 2020

I consider this resolved. With the way Angular works today, at runtime the async pipe will set a null value into inputs. I think that strictTemplates should be enforcing that this is possible, unless you explicitly opt out (strictNullInputTypes: false).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Template type checking - Angular
Verifies that component/directive bindings are assignable to their @Input() s; Obeys TypeScript's strictNullChecks flag when validating the preceding mode ...
Read more >
Angular template compilation TS2531 error with a non-null value
this is introduced by angular 9's full template type checks being combined with strict null checks and the async pipe. basically, the async ......
Read more >
Understanding Angular's Async Pipe - Thinktecture
Angular's async pipe is a tool to resolve the value of a subscribable in the template. A subscribable can be an Observable ,...
Read more >
Component testing scenarios - Angular
The waitForAsync() utility hides some asynchronous boilerplate by arranging for the tester's code to run in a special async test zone. You don't...
Read more >
Fix list for IBM WebSphere Application Server V8.5
PH45838, Issue in control region with handling connection with async read ... command leaves pipe character in Kerberos config file for encrypt types....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found