From 2468d440d9a8f318774e73dc096edeb5d9807a31 Mon Sep 17 00:00:00 2001 From: Gabe Moothart Date: Wed, 14 Sep 2016 11:06:28 -0700 Subject: [PATCH 1/3] Add readonly typings for Set and Map Similar to ReadonlyArray, these typings remove the mutation methods from Set and Map so that they can only be initialized by the constructor. --- src/lib/es2015.collection.d.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/lib/es2015.collection.d.ts b/src/lib/es2015.collection.d.ts index bde1c6d5811..9b0a484ce36 100644 --- a/src/lib/es2015.collection.d.ts +++ b/src/lib/es2015.collection.d.ts @@ -15,6 +15,21 @@ interface MapConstructor { } declare var Map: MapConstructor; +interface ReadonlyMap { + forEach( + callbackfn: (value: V, index: K, map: ReadonlyMap) => void, + thisArg?: any): void; + get(key: K): V|undefined; + has(key: K): boolean; + readonly size: number; +} + +interface ReadonlyMapConstructor { + new(entries?: [K, V][]): ReadonlyMap; + readonly prototype: ReadonlyMap; +} +declare var ReadonlyMap: ReadonlyMapConstructor; + interface WeakMap { delete(key: K): boolean; get(key: K): V | undefined; @@ -45,6 +60,19 @@ interface SetConstructor { } declare var Set: SetConstructor; +interface ReadonlySet { + forEach(callbackfn: (value: T, index: T, set: ReadonlySet) => void, thisArg?: any): + void; + has(value: T): boolean; + readonly size: number; +} + +interface ReadonlySetConstructor { + new(values?: T[]): ReadonlySet; + readonly prototype: ReadonlySet; +} +declare var ReadonlySet: ReadonlySetConstructor; + interface WeakSet { add(value: T): this; delete(value: T): boolean; From e2ee3c5c152c1f1facba341f551c1550a7cdab71 Mon Sep 17 00:00:00 2001 From: Gabe Moothart Date: Thu, 15 Sep 2016 10:33:06 -0700 Subject: [PATCH 2/3] Removed constructor typings which can't be used Also corrected some parameter names. --- src/lib/es2015.collection.d.ts | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/lib/es2015.collection.d.ts b/src/lib/es2015.collection.d.ts index 9b0a484ce36..4cdb2d187a5 100644 --- a/src/lib/es2015.collection.d.ts +++ b/src/lib/es2015.collection.d.ts @@ -1,7 +1,7 @@ interface Map { clear(): void; delete(key: K): boolean; - forEach(callbackfn: (value: V, index: K, map: Map) => void, thisArg?: any): void; + forEach(callbackfn: (value: V, key: K, map: Map) => void, thisArg?: any): void; get(key: K): V | undefined; has(key: K): boolean; set(key: K, value?: V): this; @@ -17,19 +17,13 @@ declare var Map: MapConstructor; interface ReadonlyMap { forEach( - callbackfn: (value: V, index: K, map: ReadonlyMap) => void, + callbackfn: (value: V, key: K, map: ReadonlyMap) => void, thisArg?: any): void; get(key: K): V|undefined; has(key: K): boolean; readonly size: number; } -interface ReadonlyMapConstructor { - new(entries?: [K, V][]): ReadonlyMap; - readonly prototype: ReadonlyMap; -} -declare var ReadonlyMap: ReadonlyMapConstructor; - interface WeakMap { delete(key: K): boolean; get(key: K): V | undefined; @@ -48,7 +42,7 @@ interface Set { add(value: T): this; clear(): void; delete(value: T): boolean; - forEach(callbackfn: (value: T, index: T, set: Set) => void, thisArg?: any): void; + forEach(callbackfn: (value: T, value2: T, set: Set) => void, thisArg?: any): void; has(value: T): boolean; readonly size: number; } @@ -61,18 +55,12 @@ interface SetConstructor { declare var Set: SetConstructor; interface ReadonlySet { - forEach(callbackfn: (value: T, index: T, set: ReadonlySet) => void, thisArg?: any): + forEach(callbackfn: (value: T, value2: T, set: ReadonlySet) => void, thisArg?: any): void; has(value: T): boolean; readonly size: number; } -interface ReadonlySetConstructor { - new(values?: T[]): ReadonlySet; - readonly prototype: ReadonlySet; -} -declare var ReadonlySet: ReadonlySetConstructor; - interface WeakSet { add(value: T): this; delete(value: T): boolean; From a9d4b3016ab02ca7fedeb884f9fdc36c7b695d39 Mon Sep 17 00:00:00 2001 From: Gabe Moothart Date: Thu, 15 Sep 2016 10:47:19 -0700 Subject: [PATCH 3/3] indenting --- src/lib/es2015.collection.d.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/lib/es2015.collection.d.ts b/src/lib/es2015.collection.d.ts index 4cdb2d187a5..6a2c43cd050 100644 --- a/src/lib/es2015.collection.d.ts +++ b/src/lib/es2015.collection.d.ts @@ -16,12 +16,10 @@ interface MapConstructor { declare var Map: MapConstructor; interface ReadonlyMap { - forEach( - callbackfn: (value: V, key: K, map: ReadonlyMap) => void, - thisArg?: any): void; - get(key: K): V|undefined; - has(key: K): boolean; - readonly size: number; + forEach(callbackfn: (value: V, key: K, map: ReadonlyMap) => void, thisArg?: any): void; + get(key: K): V|undefined; + has(key: K): boolean; + readonly size: number; } interface WeakMap { @@ -55,10 +53,9 @@ interface SetConstructor { declare var Set: SetConstructor; interface ReadonlySet { - forEach(callbackfn: (value: T, value2: T, set: ReadonlySet) => void, thisArg?: any): - void; - has(value: T): boolean; - readonly size: number; + forEach(callbackfn: (value: T, value2: T, set: ReadonlySet) => void, thisArg?: any): void; + has(value: T): boolean; + readonly size: number; } interface WeakSet {