Skip to content

Commit a479210

Browse files
authored
Fix types (#12)
1 parent 7de3e51 commit a479210

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ Thumbs.db
99
*.lock
1010
logs
1111
package-lock.json
12+
distribution

index.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
export default class ManyKeysMap<K, V> extends Map<K[], V> {}
1+
export default class ManyKeysMap<K extends readonly unknown[], V> extends Map<K, V> {
2+
/** @private */
3+
_publicKeys: Map<string, K>;
4+
/** @private */
5+
_symbolHashes: Map<symbol, K>;
6+
}

index.test.js renamed to index.test.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
/* eslint-disable unicorn/no-array-for-each, no-warning-comments -- It's part of the test */
1+
/* eslint-disable unicorn/no-array-for-each, no-warning-comments, @typescript-eslint/no-empty-function -- It's part of the test */
22
import {test, assert} from 'vitest';
33
import ManyKeysMap from './index.js';
44

55
// AVA adapter
6-
const t = {
6+
const t: {
7+
// TS complains https://stackoverflow.com/a/72689922/288906
8+
is: typeof assert.equal;
9+
deepEqual: typeof assert.deepEqual;
10+
true: typeof assert.isTrue;
11+
false: typeof assert.isFalse;
12+
throws: typeof assert.throws;
13+
} = {
714
is: assert.equal,
815
deepEqual: assert.deepEqual,
916
true: assert.isTrue,
@@ -23,7 +30,7 @@ test('Basics', () => {
2330
t.deepEqual([...map.entries()], []);
2431
t.deepEqual([...map.values()], []);
2532
t.deepEqual([...map.keys()], []);
26-
map.forEach(_ => t.fail());
33+
map.forEach(_ => assert.fail());
2734
});
2835

2936
test('Set', () => {
@@ -42,7 +49,7 @@ test('Set', () => {
4249
t.is(map._publicKeys.size, 3);
4350

4451
// Also make sure that the same map is returned
45-
t.is(map.set(['#', 'fifth']), map);
52+
t.is(map.set(['#', 'fifth'], 5), map);
4653

4754
const prefilledMap = new ManyKeysMap([
4855
[['-'], 'first'],
@@ -152,11 +159,13 @@ test('Clear', () => {
152159
t.is(map._publicKeys.size, 4);
153160
t.is(map._symbolHashes.size, 2); // Symbol(1) and null
154161

162+
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression -- That's the test
155163
t.is(map.clear(), undefined);
156164
t.is(map.size, 0);
157165
t.is(map._publicKeys.size, 0);
158166
t.is(map._symbolHashes.size, 0);
159167

168+
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression -- That's the test
160169
t.is(map.clear(), undefined);
161170
t.is(map.size, 0);
162171
t.is(map._publicKeys.size, 0);
@@ -168,7 +177,7 @@ test('Iterators', () => {
168177
[['-'], 'first'],
169178
[[':', '-'], 'second'],
170179
[[':', '-', '%'], 'third'],
171-
];
180+
] as Array<[unknown[], string]>;
172181
const map = new ManyKeysMap(pairs);
173182
const regularMap = new Map(pairs);
174183

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@
2424
"index.js"
2525
],
2626
"scripts": {
27-
"test": "xo && vitest"
27+
"test": "tsc && xo && vitest"
2828
},
2929
"xo": {
3030
"rules": {
3131
"no-new": 0
3232
}
3333
},
3434
"devDependencies": {
35+
"@sindresorhus/tsconfig": "^7.0.0",
36+
"typescript": "^5.8.3",
3537
"vitest": "^3.2.4",
3638
"xo": "^1.0.5"
3739
},

tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "@sindresorhus/tsconfig"
3+
}

0 commit comments

Comments
 (0)