mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user