[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:
- Created 3 years ago
- Reactions:4
- Comments:9 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@sayoojbk - a good start is to have a full read of https://github.com/angular/angular/blob/master/CONTRIBUTING.md
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 😄