From e387d22f832bc0e15b8f4a575daec454765244f8 Mon Sep 17 00:00:00 2001 From: Ben Lesh Date: Tue, 13 Apr 2021 12:39:04 -0500 Subject: [PATCH] fix(core): AsyncPipe now compatible with RxJS 7 (#41590) Adds a fix to make sure that RxJS v7 Observable is compatible with AsyncPipe. This is a typings-only change. For more information see: https://github.com/microsoft/TypeScript/issues/43643 PR Close #41590 --- goldens/public-api/common/common.d.ts | 4 ++-- packages/common/src/pipes/async_pipe.ts | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/goldens/public-api/common/common.d.ts b/goldens/public-api/common/common.d.ts index 4d3601fd08..939f137fdc 100644 --- a/goldens/public-api/common/common.d.ts +++ b/goldens/public-api/common/common.d.ts @@ -3,9 +3,9 @@ export declare const APP_BASE_HREF: InjectionToken; export declare class AsyncPipe implements OnDestroy, PipeTransform { constructor(_ref: ChangeDetectorRef); ngOnDestroy(): void; - transform(obj: Subscribable | Promise): T | null; + transform(obj: Observable | Subscribable | Promise): T | null; transform(obj: null | undefined): null; - transform(obj: Subscribable | Promise | null | undefined): T | null; + transform(obj: Observable | Subscribable | Promise | null | undefined): T | null; } export declare class CommonModule { diff --git a/packages/common/src/pipes/async_pipe.ts b/packages/common/src/pipes/async_pipe.ts index 6365dbc067..9bb43b8862 100644 --- a/packages/common/src/pipes/async_pipe.ts +++ b/packages/common/src/pipes/async_pipe.ts @@ -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'; @@ -95,10 +95,14 @@ export class AsyncPipe implements OnDestroy, PipeTransform { } } - transform(obj: Subscribable|Promise): 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(obj: Observable|Subscribable|Promise): T|null; transform(obj: null|undefined): null; - transform(obj: Subscribable|Promise|null|undefined): T|null; - transform(obj: Subscribable|Promise|null|undefined): T|null { + transform(obj: Observable|Subscribable|Promise|null|undefined): T|null; + transform(obj: Observable|Subscribable|Promise|null|undefined): T|null { if (!this._obj) { if (obj) { this._subscribe(obj);