Make Map constructor argument optional and nullable (#43396)

* Make Iterable Map constructor argument optional

Fixes #37779

* Change Map constructor in iterable to accept both null and undefined.

According to the spec (https://tc39.es/ecma262/#sec-map-iterable), the sole argument passed to Map is allowed to be null or undefined.

* Changed Map constructor to ensure new Map() still types as Map<any, any>.

* Add map constructor test.

This proves that the previous commit fixes #37779, as well as that new Map() still types as Map<any, any>.

* Update baseline.

Co-authored-by: Jared Neil <jaredneil@lucidchart.com>
This commit is contained in:
Pimm "de Chinchilla" Hogeling
2022-01-18 14:39:05 +01:00
committed by GitHub
parent 7490b329a7
commit cecd8c50a0
8 changed files with 95 additions and 10 deletions

View File

@@ -137,7 +137,8 @@ interface ReadonlyMap<K, V> {
}
interface MapConstructor {
new <K, V>(iterable: Iterable<readonly [K, V]>): Map<K, V>;
new(): Map<any, any>;
new <K, V>(iterable?: Iterable<readonly [K, V]> | null): Map<K, V>;
}
interface WeakMap<K extends object, V> { }