refactor(common): improve type of AsyncPipe._strategy field (#46128)

The field's type does not account for the `null` value that is assigned
in the field's initializer. This commit includes `null` in the type for
better type-safety. Exising reads are updated with a non-null assertion
operation in places where initialization is known to have occurred.

PR Close #46128
This commit is contained in:
JoostK
2022-05-24 22:07:55 +02:00
committed by Alex Rickabaugh
parent 0206c10f8e
commit 8eb1b386b2
+6 -3
View File
@@ -86,7 +86,7 @@ export class AsyncPipe implements OnDestroy, PipeTransform {
private _subscription: Unsubscribable|Promise<any>|null = null;
private _obj: Subscribable<any>|Promise<any>|EventEmitter<any>|null = null;
private _strategy: SubscriptionStrategy = null!;
private _strategy: SubscriptionStrategy|null = null;
constructor(private _ref: ChangeDetectorRef) {}
@@ -126,7 +126,8 @@ export class AsyncPipe implements OnDestroy, PipeTransform {
obj, (value: Object) => this._updateLatestValue(obj, value));
}
private _selectStrategy(obj: Subscribable<any>|Promise<any>|EventEmitter<any>): any {
private _selectStrategy(obj: Subscribable<any>|Promise<any>|
EventEmitter<any>): SubscriptionStrategy {
if (ɵisPromise(obj)) {
return _promiseStrategy;
}
@@ -139,7 +140,9 @@ export class AsyncPipe implements OnDestroy, PipeTransform {
}
private _dispose(): void {
this._strategy.dispose(this._subscription!);
// Note: `dispose` is only called if a subscription has been initialized before, indicating
// that `this._strategy` is also available.
this._strategy!.dispose(this._subscription!);
this._latestValue = null;
this._subscription = null;
this._obj = null;