Skip to content

Commit b93fc1f

Browse files
authored
Merge pull request #207 from amitdahan/fix-non-generic-map-constructor
Fix `new Map()` always returning `Map<unknown, unknown>`
2 parents cfc8c1a + 922f8a8 commit b93fc1f

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/entrypoints/map-constructor.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
interface MapConstructor {
2-
new (): Map<unknown, unknown>;
2+
new <K = unknown, V = unknown>(): Map<K, V>;
33
}

src/tests/map-constructor.ts

+26
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,29 @@ doNotExecute(() => {
5959

6060
type testClear = [Expect<Equal<typeof cleared, void>>];
6161
});
62+
63+
doNotExecute(() => {
64+
const map = new Map() satisfies Map<string, boolean>;
65+
type test = [Expect<Equal<typeof map, Map<string, boolean>>>];
66+
});
67+
68+
doNotExecute(() => {
69+
const map: Map<string, boolean> = new Map();
70+
type test = [Expect<Equal<typeof map, Map<string, boolean>>>];
71+
});
72+
73+
doNotExecute(() => {
74+
function expectsBooleanMap(map: Map<string, boolean>) {
75+
return map;
76+
}
77+
const map = expectsBooleanMap(new Map());
78+
type test = [Expect<Equal<typeof map, Map<string, boolean>>>];
79+
});
80+
81+
doNotExecute(() => {
82+
const map = new Map([
83+
["foo", 1],
84+
["bar", 2],
85+
]);
86+
type test = [Expect<Equal<typeof map, Map<string, number>>>];
87+
});

0 commit comments

Comments
 (0)