Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix new Map() always returning Map<unknown, unknown> #207

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/entrypoints/map-constructor.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
interface MapConstructor {
new (): Map<unknown, unknown>;
new <K = unknown, V = unknown>(): Map<K, V>;
}
26 changes: 26 additions & 0 deletions src/tests/map-constructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,29 @@ doNotExecute(() => {

type testClear = [Expect<Equal<typeof cleared, void>>];
});

doNotExecute(() => {
const map = new Map() satisfies Map<string, boolean>;
type test = [Expect<Equal<typeof map, Map<string, boolean>>>];
});

doNotExecute(() => {
amitdahan marked this conversation as resolved.
Show resolved Hide resolved
const map: Map<string, boolean> = new Map();
type test = [Expect<Equal<typeof map, Map<string, boolean>>>];
});

doNotExecute(() => {
function expectsBooleanMap(map: Map<string, boolean>) {
return map;
}
const map = expectsBooleanMap(new Map());
type test = [Expect<Equal<typeof map, Map<string, boolean>>>];
});

doNotExecute(() => {
const map = new Map([
["foo", 1],
["bar", 2],
]);
type test = [Expect<Equal<typeof map, Map<string, number>>>];
});