From 33734537364988295711676ddbc7930679cf54a4 Mon Sep 17 00:00:00 2001 From: Ajit Singh Date: Thu, 28 May 2020 09:10:59 +0530 Subject: [PATCH] feat(common): add ReadonlyMap in place of Map in keyValuePipe (#37311) ReadonlyMap is a superset of Map, in keyValuePipe we do not change the value of the object so ReadonlyPipe Works right in this case and we can accomodate more types. To accomodate more types added ReadonlyMap in Key Value pipe. Fixes #37308 PR Close #37311 --- goldens/public-api/common/common.d.ts | 12 ++++++------ packages/common/src/pipes/keyvalue_pipe.ts | 21 +++++++++++---------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/goldens/public-api/common/common.d.ts b/goldens/public-api/common/common.d.ts index c36711e0fd..8a6d5c0155 100644 --- a/goldens/public-api/common/common.d.ts +++ b/goldens/public-api/common/common.d.ts @@ -138,18 +138,18 @@ export declare class KeyValuePipe implements PipeTransform { transform(input: null, compareFn?: (a: KeyValue, b: KeyValue) => number): null; transform(input: { [key: string]: V; - } | Map, compareFn?: (a: KeyValue, b: KeyValue) => number): Array>; + } | ReadonlyMap, compareFn?: (a: KeyValue, b: KeyValue) => number): Array>; transform(input: { [key: string]: V; - } | Map | null, compareFn?: (a: KeyValue, b: KeyValue) => number): Array> | null; + } | ReadonlyMap | null, compareFn?: (a: KeyValue, b: KeyValue) => number): Array> | null; transform(input: { [key: number]: V; - } | Map, compareFn?: (a: KeyValue, b: KeyValue) => number): Array>; + } | ReadonlyMap, compareFn?: (a: KeyValue, b: KeyValue) => number): Array>; transform(input: { [key: number]: V; - } | Map | null, compareFn?: (a: KeyValue, b: KeyValue) => number): Array> | null; - transform(input: Map, compareFn?: (a: KeyValue, b: KeyValue) => number): Array>; - transform(input: Map | null, compareFn?: (a: KeyValue, b: KeyValue) => number): Array> | null; + } | ReadonlyMap | null, compareFn?: (a: KeyValue, b: KeyValue) => number): Array> | null; + transform(input: ReadonlyMap, compareFn?: (a: KeyValue, b: KeyValue) => number): Array>; + transform(input: ReadonlyMap | null, compareFn?: (a: KeyValue, b: KeyValue) => number): Array> | null; } export declare class Location { diff --git a/packages/common/src/pipes/keyvalue_pipe.ts b/packages/common/src/pipes/keyvalue_pipe.ts index 19730731b1..e81fff1326 100644 --- a/packages/common/src/pipes/keyvalue_pipe.ts +++ b/packages/common/src/pipes/keyvalue_pipe.ts @@ -36,8 +36,8 @@ export interface KeyValue { * @usageNotes * ### Examples * - * This examples show how an Object or a Map can be iterated by ngFor with the use of this keyvalue - * pipe. + * This examples show how an Object or a Map can be iterated by ngFor with the use of this + * keyvalue pipe. * * {@example common/pipes/ts/keyvalue_pipe.ts region='KeyValuePipe'} * @@ -52,28 +52,29 @@ export class KeyValuePipe implements PipeTransform { transform(input: null, compareFn?: (a: KeyValue, b: KeyValue) => number): null; transform( - input: {[key: string]: V}|Map, + input: {[key: string]: V}|ReadonlyMap, compareFn?: (a: KeyValue, b: KeyValue) => number): Array>; transform( - input: {[key: string]: V}|Map|null, + input: {[key: string]: V}|ReadonlyMap|null, compareFn?: (a: KeyValue, b: KeyValue) => number): Array>|null; transform( - input: {[key: number]: V}|Map, + input: {[key: number]: V}|ReadonlyMap, compareFn?: (a: KeyValue, b: KeyValue) => number): Array>; transform( - input: {[key: number]: V}|Map|null, + input: {[key: number]: V}|ReadonlyMap|null, compareFn?: (a: KeyValue, b: KeyValue) => number): Array>|null; - transform(input: Map, compareFn?: (a: KeyValue, b: KeyValue) => number): - Array>; transform( - input: Map|null, + input: ReadonlyMap, + compareFn?: (a: KeyValue, b: KeyValue) => number): Array>; + transform( + input: ReadonlyMap|null, compareFn?: (a: KeyValue, b: KeyValue) => number): Array>|null; transform( - input: null|{[key: string]: V, [key: number]: V}|Map, + input: null|{[key: string]: V, [key: number]: V}|ReadonlyMap, compareFn: (a: KeyValue, b: KeyValue) => number = defaultComparator): Array>|null { if (!input || (!(input instanceof Map) && typeof input !== 'object')) {