From 4da7925ad503db6ef4bdf96b7baaf04596ee41c3 Mon Sep 17 00:00:00 2001 From: Chuck Jazdzewski Date: Tue, 31 Jan 2017 18:11:18 -0800 Subject: [PATCH] feat(common): added typed overloaded for `AsyncPipe.transform()` (#14367) BREAKING CHANGE: Classes that derive from `AsyncPipe` and override `transform()` might not compile correctly. Use of `async` pipe in templates is unaffected. Mitigation: Update derived classes of `AsyncPipe` that override `transform()` to include the type parameter overloads. Related to #12398 PR Close #14367 --- modules/@angular/common/src/pipes/async_pipe.ts | 5 ++++- tools/public_api_guard/common/index.d.ts | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/@angular/common/src/pipes/async_pipe.ts b/modules/@angular/common/src/pipes/async_pipe.ts index 59af55ab80..3c21fd13c0 100644 --- a/modules/@angular/common/src/pipes/async_pipe.ts +++ b/modules/@angular/common/src/pipes/async_pipe.ts @@ -82,6 +82,9 @@ export class AsyncPipe implements OnDestroy, PipeTransform { } } + transform(obj: Observable): T|null; + transform(obj: Promise): T|null; + transform(obj: EventEmitter): T|null; transform(obj: Observable|Promise|EventEmitter): any { if (!this._obj) { if (obj) { @@ -93,7 +96,7 @@ export class AsyncPipe implements OnDestroy, PipeTransform { if (obj !== this._obj) { this._dispose(); - return this.transform(obj); + return this.transform(obj as any); } if (this._latestValue === this._latestReturnedValue) { diff --git a/tools/public_api_guard/common/index.d.ts b/tools/public_api_guard/common/index.d.ts index c86bbffa57..5a81a9b079 100644 --- a/tools/public_api_guard/common/index.d.ts +++ b/tools/public_api_guard/common/index.d.ts @@ -5,7 +5,9 @@ export declare const APP_BASE_HREF: InjectionToken; export declare class AsyncPipe implements OnDestroy, PipeTransform { constructor(_ref: ChangeDetectorRef); ngOnDestroy(): void; - transform(obj: Observable | Promise | EventEmitter): any; + transform(obj: EventEmitter): T | null; + transform(obj: Promise): T | null; + transform(obj: Observable): T | null; } /** @stable */