Skip to content

Commit

Permalink
fix(core): AsyncPipe now compatible with RxJS 7 (#41590)
Browse files Browse the repository at this point in the history
Adds a fix to make sure that RxJS v7 Observable is compatible with AsyncPipe. This is a typings-only change.
For more information see: microsoft/TypeScript#43643

PR Close #41590
  • Loading branch information
benlesh authored and mhevery committed May 4, 2021
1 parent b3cd128 commit e387d22
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions goldens/public-api/common/common.d.ts
Expand Up @@ -3,9 +3,9 @@ export declare const APP_BASE_HREF: InjectionToken<string>;
export declare class AsyncPipe implements OnDestroy, PipeTransform {
constructor(_ref: ChangeDetectorRef);
ngOnDestroy(): void;
transform<T>(obj: Subscribable<T> | Promise<T>): T | null;
transform<T>(obj: Observable<T> | Subscribable<T> | Promise<T>): T | null;
transform<T>(obj: null | undefined): null;
transform<T>(obj: Subscribable<T> | Promise<T> | null | undefined): T | null;
transform<T>(obj: Observable<T> | Subscribable<T> | Promise<T> | null | undefined): T | null;
}

export declare class CommonModule {
Expand Down
12 changes: 8 additions & 4 deletions packages/common/src/pipes/async_pipe.ts
Expand Up @@ -7,7 +7,7 @@
*/

import {ChangeDetectorRef, EventEmitter, OnDestroy, Pipe, PipeTransform, ɵisPromise, ɵisSubscribable} from '@angular/core';
import {Subscribable, Unsubscribable} from 'rxjs';
import {Observable, Subscribable, Unsubscribable} from 'rxjs';

import {invalidPipeArgumentError} from './invalid_pipe_argument_error';

Expand Down Expand Up @@ -95,10 +95,14 @@ export class AsyncPipe implements OnDestroy, PipeTransform {
}
}

transform<T>(obj: Subscribable<T>|Promise<T>): T|null;
// NOTE(@benlesh): Because Observable has deprecated a few call patterns for `subscribe`,
// TypeScript has a hard time matching Observable to Subscribable, for more information
// see https://github.com/microsoft/TypeScript/issues/43643

transform<T>(obj: Observable<T>|Subscribable<T>|Promise<T>): T|null;
transform<T>(obj: null|undefined): null;
transform<T>(obj: Subscribable<T>|Promise<T>|null|undefined): T|null;
transform<T>(obj: Subscribable<T>|Promise<T>|null|undefined): T|null {
transform<T>(obj: Observable<T>|Subscribable<T>|Promise<T>|null|undefined): T|null;
transform<T>(obj: Observable<T>|Subscribable<T>|Promise<T>|null|undefined): T|null {
if (!this._obj) {
if (obj) {
this._subscribe(obj);
Expand Down

0 comments on commit e387d22

Please sign in to comment.