diff --git a/goldens/public-api/common/common.d.ts b/goldens/public-api/common/common.d.ts index 12574a6997..df57950d36 100644 --- a/goldens/public-api/common/common.d.ts +++ b/goldens/public-api/common/common.d.ts @@ -110,7 +110,7 @@ export declare class HashLocationStrategy extends LocationStrategy { export declare class I18nPluralPipe implements PipeTransform { constructor(_localization: NgLocalization); - transform(value: number, pluralMap: { + transform(value: number | null | undefined, pluralMap: { [count: string]: string; }, locale?: string): string; } diff --git a/packages/common/src/pipes/i18n_plural_pipe.ts b/packages/common/src/pipes/i18n_plural_pipe.ts index a0956167b0..252da96c3e 100644 --- a/packages/common/src/pipes/i18n_plural_pipe.ts +++ b/packages/common/src/pipes/i18n_plural_pipe.ts @@ -39,7 +39,8 @@ export class I18nPluralPipe implements PipeTransform { * @param locale a `string` defining the locale to use (uses the current {@link LOCALE_ID} by * default). */ - transform(value: number, pluralMap: {[count: string]: string}, locale?: string): string { + transform(value: number|null|undefined, pluralMap: {[count: string]: string}, locale?: string): + string { if (value == null) return ''; if (typeof pluralMap !== 'object' || pluralMap === null) { diff --git a/packages/common/test/pipes/i18n_plural_pipe_spec.ts b/packages/common/test/pipes/i18n_plural_pipe_spec.ts index 0140768624..19757f367d 100644 --- a/packages/common/test/pipes/i18n_plural_pipe_spec.ts +++ b/packages/common/test/pipes/i18n_plural_pipe_spec.ts @@ -54,12 +54,17 @@ import {JitReflector} from '@angular/platform-browser-dynamic/src/compiler_refle }); it('should use "" if value is undefined', () => { - const val = pipe.transform(void (0) as any, mapping); + const val = pipe.transform(undefined, mapping); + expect(val).toEqual(''); + }); + + it('should use "" if value is null', () => { + const val = pipe.transform(null, mapping); expect(val).toEqual(''); }); it('should not support bad arguments', () => { - expect(() => pipe.transform(0, 'hey')).toThrowError(); + expect(() => pipe.transform(0, 'hey' as any)).toThrowError(); }); }); }); diff --git a/packages/common/test/pipes/i18n_select_pipe_spec.ts b/packages/common/test/pipes/i18n_select_pipe_spec.ts index e8f8c43c1f..776c62131e 100644 --- a/packages/common/test/pipes/i18n_select_pipe_spec.ts +++ b/packages/common/test/pipes/i18n_select_pipe_spec.ts @@ -40,7 +40,7 @@ import {JitReflector} from '@angular/platform-browser-dynamic/src/compiler_refle }); it('should throw on bad arguments', () => { - expect(() => pipe.transform('male', 'hey')).toThrowError(); + expect(() => pipe.transform('male', 'hey' as any)).toThrowError(); }); }); });