Un-consolidate overloads for Map and WeakMap (#28052)

This commit is contained in:
Andy
2018-10-22 11:18:56 -07:00
committed by GitHub
parent 8e0142d709
commit afa94c527c
7 changed files with 28 additions and 2 deletions

View File

@@ -9,7 +9,8 @@ interface Map<K, V> {
}
interface MapConstructor {
new <K = any, V = any>(entries?: ReadonlyArray<[K, V]> | null): Map<K, V>;
new(): Map<any, any>;
new<K, V>(entries?: ReadonlyArray<[K, V]> | null): Map<K, V>;
readonly prototype: Map<any, any>;
}
declare var Map: MapConstructor;

View File

@@ -135,7 +135,7 @@ interface MapConstructor {
interface WeakMap<K extends object, V> { }
interface WeakMapConstructor {
new <K extends object = object, V = any>(iterable: Iterable<[K, V]>): WeakMap<K, V>;
new <K extends object, V>(iterable: Iterable<[K, V]>): WeakMap<K, V>;
}
interface Set<T> {

View File

@@ -0,0 +1,8 @@
tests/cases/compiler/newMap.ts(1,9): error TS2558: Expected 0-2 type arguments, but got 1.
==== tests/cases/compiler/newMap.ts (1 errors) ====
new Map<string>();
~~~~~~
!!! error TS2558: Expected 0-2 type arguments, but got 1.

View File

@@ -0,0 +1,6 @@
//// [newMap.ts]
new Map<string>();
//// [newMap.js]
new Map();

View File

@@ -0,0 +1,4 @@
=== tests/cases/compiler/newMap.ts ===
new Map<string>();
>Map : Symbol(Map, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))

View File

@@ -0,0 +1,5 @@
=== tests/cases/compiler/newMap.ts ===
new Map<string>();
>new Map<string>() : any
>Map : MapConstructor

View File

@@ -0,0 +1,2 @@
// @lib: es6
new Map<string>();