diff --git a/packages/common/src/pipes/async_pipe.ts b/packages/common/src/pipes/async_pipe.ts index e53de751d9..ce1f555b58 100644 --- a/packages/common/src/pipes/async_pipe.ts +++ b/packages/common/src/pipes/async_pipe.ts @@ -85,8 +85,8 @@ export class AsyncPipe implements OnDestroy, PipeTransform { transform(obj: null): null; transform(obj: undefined): undefined; - transform(obj: Observable): T|null; - transform(obj: Promise): T|null; + transform(obj: Observable|null|undefined): T|null; + transform(obj: Promise|null|undefined): T|null; transform(obj: Observable|Promise|null|undefined): any { if (!this._obj) { if (obj) { diff --git a/packages/compiler-cli/test/diagnostics/check_types_spec.ts b/packages/compiler-cli/test/diagnostics/check_types_spec.ts index f125a5f2ab..5305a431ef 100644 --- a/packages/compiler-cli/test/diagnostics/check_types_spec.ts +++ b/packages/compiler-cli/test/diagnostics/check_types_spec.ts @@ -620,12 +620,12 @@ describe('ng type checker', () => { }); }); - describe('regressions ', () => { + describe('core', () => { const a = (files: MockFiles, options: ng.AngularCompilerOptions = {}) => { accept(files, {fullTemplateTypeCheck: true, ...options}); }; - // #19905 + // Regression #19905 it('should accept an event binding', () => { a({ 'src/app.component.ts': '', @@ -655,6 +655,38 @@ describe('ng type checker', () => { }); }); + describe('common', () => { + const a = (files: MockFiles, options: ng.AngularCompilerOptions = {}) => { + accept(files, {fullTemplateTypeCheck: true, ...options}); + }; + + // Regression #19905 + it('should accept a |undefined or |null parameter for async_pipe', () => { + a({ + 'src/app.component.ts': '', + 'src/lib.ts': '', + 'src/app.module.ts': ` + import {NgModule, Component} from '@angular/core'; + import {CommonModule} from '@angular/common'; + + @Component({ + selector: 'comp', + template: '
{{ name | async}}
' + }) + export class MainComp { + name: Promise|undefined; + } + + + @NgModule({ + declarations: [MainComp], + imports: [CommonModule] + }) + export class MainModule {}` + }); + }); + }); + describe('with modified quickstart (fullTemplateTypeCheck: false)', () => { addTests({fullTemplateTypeCheck: false}); }); diff --git a/tools/public_api_guard/common/common.d.ts b/tools/public_api_guard/common/common.d.ts index d4fe448659..37fe2ba69e 100644 --- a/tools/public_api_guard/common/common.d.ts +++ b/tools/public_api_guard/common/common.d.ts @@ -5,8 +5,8 @@ export declare const APP_BASE_HREF: InjectionToken; export declare class AsyncPipe implements OnDestroy, PipeTransform { constructor(_ref: ChangeDetectorRef); ngOnDestroy(): void; - transform(obj: Promise): T | null; - transform(obj: Observable): T | null; + transform(obj: Promise | null | undefined): T | null; + transform(obj: Observable | null | undefined): T | null; transform(obj: undefined): undefined; transform(obj: null): null; }