Skip to content

Commit 9d8d2b6

Browse files
authored
Merge pull request #10921 from gmoothart/readonly-collections
Add readonly typings for Set and Map
2 parents 10b3d73 + a9d4b30 commit 9d8d2b6

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/lib/es2015.collection.d.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
interface Map<K, V> {
22
clear(): void;
33
delete(key: K): boolean;
4-
forEach(callbackfn: (value: V, index: K, map: Map<K, V>) => void, thisArg?: any): void;
4+
forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void;
55
get(key: K): V | undefined;
66
has(key: K): boolean;
77
set(key: K, value?: V): this;
@@ -15,6 +15,13 @@ interface MapConstructor {
1515
}
1616
declare var Map: MapConstructor;
1717

18+
interface ReadonlyMap<K, V> {
19+
forEach(callbackfn: (value: V, key: K, map: ReadonlyMap<K, V>) => void, thisArg?: any): void;
20+
get(key: K): V|undefined;
21+
has(key: K): boolean;
22+
readonly size: number;
23+
}
24+
1825
interface WeakMap<K, V> {
1926
delete(key: K): boolean;
2027
get(key: K): V | undefined;
@@ -33,7 +40,7 @@ interface Set<T> {
3340
add(value: T): this;
3441
clear(): void;
3542
delete(value: T): boolean;
36-
forEach(callbackfn: (value: T, index: T, set: Set<T>) => void, thisArg?: any): void;
43+
forEach(callbackfn: (value: T, value2: T, set: Set<T>) => void, thisArg?: any): void;
3744
has(value: T): boolean;
3845
readonly size: number;
3946
}
@@ -45,6 +52,12 @@ interface SetConstructor {
4552
}
4653
declare var Set: SetConstructor;
4754

55+
interface ReadonlySet<T> {
56+
forEach(callbackfn: (value: T, value2: T, set: ReadonlySet<T>) => void, thisArg?: any): void;
57+
has(value: T): boolean;
58+
readonly size: number;
59+
}
60+
4861
interface WeakSet<T> {
4962
add(value: T): this;
5063
delete(value: T): boolean;

0 commit comments

Comments
 (0)