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 for issue 41 - change Map to unknown #53

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions package.json
Expand Up @@ -58,6 +58,11 @@
"import": "./dist/set-has.mjs",
"default": "./dist/set-has.js"
},
"./map-constructor": {
"types": "./dist/map-constructor.d.ts",
"import": "./dist/map-constructor.mjs",
"default": "./dist/map-constructor.js"
},
"./utils": {
"types": "./dist/utils.d.ts",
"import": "./dist/utils.mjs",
Expand Down
3 changes: 3 additions & 0 deletions src/entrypoints/map-constructor.d.ts
@@ -0,0 +1,3 @@
interface MapConstructor {
new(): Map<unknown, unknown>
}
1 change: 1 addition & 0 deletions src/entrypoints/recommended.d.ts
Expand Up @@ -4,3 +4,4 @@
/// <reference path="json-parse.d.ts" />
/// <reference path="array-includes.d.ts" />
/// <reference path="set-has.d.ts" />
/// <reference path="map-constructor.d.ts" />
61 changes: 61 additions & 0 deletions src/tests/map-constructor.ts
@@ -0,0 +1,61 @@
import {doNotExecute, Equal, Expect} from "./utils";

doNotExecute(() => {
const map = new Map();

const result = map.get('foo');

type test = [Expect<Equal<typeof result, unknown>>];
});

doNotExecute(() => {
const map = new Map();

map.set('Jessie', {phone: '213-555-1234', address: '123 N 1st Ave'});

const result = map.has('Jessie');

type test = [Expect<Equal<typeof result, boolean>>];
});

doNotExecute(() => {
const map = new Map();

map.set('Jessie', {phone: '213-555-1234', address: '123 N 1st Ave'});

const result = map.get('Jessie');

type test = [Expect<Equal<typeof result, unknown>>];
});

doNotExecute(() => {
const map = new Map();

map.set('Jessie', {phone: '213-555-1234', address: '123 N 1st Ave'});

const result = map.delete('Jessie');

type test = [Expect<Equal<typeof result, boolean>>];
});

doNotExecute(() => {
const map = new Map();

map.set('Jessie', {phone: '213-555-1234', address: '123 N 1st Ave'});
map.set('Hilary', {phone: '617-555-4321', address: '321 S 2nd St'});

const size = map.size;

type testSize = [Expect<Equal<typeof size, number>>];
});

doNotExecute(() => {
const map = new Map();

map.set('Jessie', {phone: '213-555-1234', address: '123 N 1st Ave'});
map.set('Hilary', {phone: '617-555-4321', address: '321 S 2nd St'});

const cleared = map.clear();

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