-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do thisYou can do this
Milestone
Description
TypeScript Version: 3.8.3
Search Terms: Map MapConstructor Iterable Iterator
Code
let undefinedArray: [string, string][] | undefined;
const map1 = new Map(undefinedArray);
let definedInterable: IterableIterator<[string, string]> = new Set<string>().entries();
const map2 = new Map(definedInterable);
let undefinedIterable: IterableIterator<[string, string]> | undefined;
const map3 = new Map(undefinedIterable); // Type error hereExpected behavior:
Passes type check because new Map(undefined) is a valid call to the Map constructor.
Actual behavior:
No overload matches this call.
Overload 1 of 4, '(iterable: Iterable<readonly [string, string]>): Map<string, string>', gave the following error.
Argument of type 'IterableIterator<[string, string]> | undefined' is not assignable to parameter of type 'Iterable<readonly [string, string]>'.
Type 'undefined' is not assignable to type 'Iterable<readonly [string, string]>'.
Overload 2 of 4, '(iterable: Iterable<readonly [string, string]>): Map<string, string>', gave the following error.
Argument of type 'IterableIterator<[string, string]> | undefined' is not assignable to parameter of type 'Iterable<readonly [string, string]>'.
Type 'undefined' is not assignable to type 'Iterable<readonly [string, string]>'.
Overload 3 of 4, '(entries?: readonly (readonly [unknown, unknown])[] | null | undefined): Map<unknown, unknown>', gave the following error.
Argument of type 'IterableIterator<[string, string]> | undefined' is not assignable to parameter of type 'readonly (readonly [unknown, unknown])[] | null | undefined'.
Type 'IterableIterator<[string, string]>' is missing the following properties from type 'readonly (readonly [unknown, unknown])[]': length, concat, join, slice, and 14 more.(2769)
Related Issues: None
Suggested Fix:
The MapConstructor interface in es2015.iterable.d.ts should accept a single optional argument.
diff --git a/src/lib/es2015.iterable.d.ts b/src/lib/es2015.iterable.d.ts
index 374aad9322..6f9b786c1d 100644
--- a/src/lib/es2015.iterable.d.ts
+++ b/src/lib/es2015.iterable.d.ts
@@ -137,7 +137,7 @@ interface ReadonlyMap<K, V> {
}
interface MapConstructor {
- new <K, V>(iterable: Iterable<readonly [K, V]>): Map<K, V>;
+ new <K, V>(iterable?: Iterable<readonly [K, V]>): Map<K, V>;
}
interface WeakMap<K extends object, V> { }Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do thisYou can do this