Skip to content

Commit 2468d44

Browse files
authored
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.
1 parent 5e3e0d6 commit 2468d44

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/lib/es2015.collection.d.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ interface MapConstructor {
1515
}
1616
declare var Map: MapConstructor;
1717

18+
interface ReadonlyMap<K, V> {
19+
forEach(
20+
callbackfn: (value: V, index: K, map: ReadonlyMap<K, V>) => void,
21+
thisArg?: any): void;
22+
get(key: K): V|undefined;
23+
has(key: K): boolean;
24+
readonly size: number;
25+
}
26+
27+
interface ReadonlyMapConstructor {
28+
new<K, V>(entries?: [K, V][]): ReadonlyMap<K, V>;
29+
readonly prototype: ReadonlyMap<any, any>;
30+
}
31+
declare var ReadonlyMap: ReadonlyMapConstructor;
32+
1833
interface WeakMap<K, V> {
1934
delete(key: K): boolean;
2035
get(key: K): V | undefined;
@@ -45,6 +60,19 @@ interface SetConstructor {
4560
}
4661
declare var Set: SetConstructor;
4762

63+
interface ReadonlySet<T> {
64+
forEach(callbackfn: (value: T, index: T, set: ReadonlySet<T>) => void, thisArg?: any):
65+
void;
66+
has(value: T): boolean;
67+
readonly size: number;
68+
}
69+
70+
interface ReadonlySetConstructor {
71+
new<T>(values?: T[]): ReadonlySet<T>;
72+
readonly prototype: ReadonlySet<any>;
73+
}
74+
declare var ReadonlySet: ReadonlySetConstructor;
75+
4876
interface WeakSet<T> {
4977
add(value: T): this;
5078
delete(value: T): boolean;

0 commit comments

Comments
 (0)