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.

[strictNullChecks] AsyncPipe should return undefined instead of null

See original GitHub issue

🚀 feature request

Relevant Package

This feature request is for @angular/core.

Description

Currently, the AsyncPipe uses null a possible return type, for a better strictNullChecks support , it should return undefined.

export declare class AsyncPipe implements OnDestroy, PipeTransform {
  // ...
  transform<T>(obj: Observable<T> | null | undefined): T | null;
  transform<T>(obj: Promise<T> | null | undefined): T | null;
}

To work around this, components that have an optional @Input() property have to define the possible types as T | null | undefined, instead of just using T | undefined.

Describe the solution you’d like

Add undefined as a possible return type for the transform() method, but keep null as the actual value and add a deprecation message.

And in a new major version, update the pipe to return undefined instead of null.

export declare class AsyncPipe implements OnDestroy, PipeTransform {
  // ...
  transform<T>(obj: Observable<T> | null | undefined): T | undefined;
  transform<T>(obj: Promise<T> | null | undefined): T | undefined;
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
petebacondarwincommented, Sep 18, 2020
1reaction
sayoojbkcommented, Sep 18, 2020

Hi, @SchnWalter @AndrewKushnir could I work on this issue. I have been using Angular for the past couple of months and would like it if I could contribute to this issue. I just started out with open-source contributions so few relevant links for support would be helpful 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

angular and async pipe typescript complains for null
Setting the option strictNullInputTypes to false disables strict null checks within Angular templates. This flag applies for all components ...
Read more >
strictNullChecks - TSConfig Option - TypeScript
When strictNullChecks is false , null and undefined are effectively ignored by the language. This can lead to unexpected errors at runtime.
Read more >
Template type checking - Angular
The strictTemplates family of compiler options should be used instead. ... null | undefined if the library was not written with strictNullChecks in...
Read more >
Pains with Ivy, Async Pipe and strictNullChecks : r/Angular2
But async's return type means we have to deal with the null somehow even if it will never be emitted. I've created a...
Read more >
Angular compilation restrictions overview
strictBindCallApply; strictFunctionTypes; strictNullChecks ... null and undefined types are distinguishable, so Typescript will recognize ...
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