Skip to content

Commit e1022b6

Browse files
committed
fix: expand typing
1 parent 4cb0ec1 commit e1022b6

File tree

3 files changed

+12
-53
lines changed

3 files changed

+12
-53
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,11 @@
4141
"@types/debug": "^4.1.5",
4242
"@types/ioredis": "^4.22.3",
4343
"@types/mocha": "^8.2.2",
44-
"@types/node": "^14.14.39",
44+
"@types/node": "^14.14.41",
4545
"@types/sinon": "^10.0.0",
4646
"@types/uuid": "^8.3.0",
4747
"@typescript-eslint/eslint-plugin": "^4.22.0",
4848
"@typescript-eslint/parser": "^4.22.0",
49-
"chai": "^4.2.0",
50-
"chai-spies": "^1.0.0",
5149
"cross-env": "^7.0.3",
5250
"eslint": "^7.24.0",
5351
"eslint-config-makeomatic": "^5.0.4",

src/callback-queue.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ const callbackQueue = new Map<string, Set<Thunk>>()
1010

1111
// cache reference
1212
const nextTick = (typeof setImmediate === 'function' && setImmediate) || process.nextTick
13-
export type Thunk = (...args: unknown[]) => unknown
13+
export type Thunk<T extends any[] = any[], R = any> = (...args: T) => R
1414

1515
/**
1616
* Iterates over callbacks and calls them with passed args
1717
* @param bucket
1818
* @param args
1919
*/
20-
function iterateOverCallbacks(bucket: Set<Thunk>, args: unknown[]) {
20+
function iterateOverCallbacks<T extends Thunk<U, R>, U extends any[] = any[], R = any>(bucket: Set<T>, args: U) {
2121
// set iterator
2222
for (const thunk of bucket) {
2323
nextTick(thunk, ...args)
@@ -35,7 +35,7 @@ function iterateOverCallbacks(bucket: Set<Thunk>, args: unknown[]) {
3535
* @param {String} key - unique key, based on which requests are bucketed
3636
* @param {Function} callback - callback that should be added into requests queue
3737
*/
38-
export function add(key: string, callback: Thunk): Thunk | false {
38+
export function add<T extends any[] = any[], R = any, X extends Thunk<T, R> = Thunk<T, R>>(key: string, callback: X): Thunk | false {
3939
assert.strictEqual(typeof key, 'string', 'key must be a truthy string')
4040
assert.ok(key, 'key must be a truthy string')
4141
assert.strictEqual(typeof callback, 'function', 'callback must be a function')
@@ -53,7 +53,7 @@ export function add(key: string, callback: Thunk): Thunk | false {
5353
* Returns forwarder function that needs to be invoked
5454
* when data has been processed
5555
*/
56-
return function forwarder(...args: unknown[]) {
56+
return function forwarder(...args: T): null | void {
5757
// its essential that we do not use any reference, because of GC
5858
// when object reaches certain number of nullified values - its recreated using compactObject
5959
// function. Therefore we need to grab a reference when callback needs to be invoked and not at

yarn.lock

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -852,11 +852,16 @@
852852
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-8.2.2.tgz#91daa226eb8c2ff261e6a8cbf8c7304641e095e0"
853853
integrity sha512-Lwh0lzzqT5Pqh6z61P3c3P5nm6fzQK/MMHl9UKeneAeInVflBSz1O2EkX6gM6xfJd7FBXBY5purtLx7fUiZ7Hw==
854854

855-
"@types/node@*", "@types/node@^14.14.39":
855+
"@types/node@*":
856856
version "14.14.39"
857857
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.39.tgz#9ef394d4eb52953d2890e4839393c309aa25d2d1"
858858
integrity sha512-Qipn7rfTxGEDqZiezH+wxqWYR8vcXq5LRpZrETD19Gs4o8LbklbmqotSUsMU+s5G3PJwMRDfNEYoxrcBwIxOuw==
859859

860+
"@types/node@^14.14.41":
861+
version "14.14.41"
862+
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.41.tgz#d0b939d94c1d7bd53d04824af45f1139b8c45615"
863+
integrity sha512-dueRKfaJL4RTtSa7bWeTK1M+VH+Gns73oCgzvYfHZywRCoPSd8EkXBL0mZ9unPTveBn+D9phZBaxuzpwjWkW0g==
864+
860865
"@types/normalize-package-data@^2.4.0":
861866
version "2.4.0"
862867
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e"
@@ -1190,11 +1195,6 @@ assert-plus@1.0.0, assert-plus@^1.0.0:
11901195
resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-1.0.0.tgz#f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525"
11911196
integrity sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=
11921197

1193-
assertion-error@^1.1.0:
1194-
version "1.1.0"
1195-
resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b"
1196-
integrity sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==
1197-
11981198
astral-regex@^2.0.0:
11991199
version "2.0.0"
12001200
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-2.0.0.tgz#483143c567aeed4785759c0865786dc77d7d2e31"
@@ -1398,23 +1398,6 @@ caseless@~0.12.0:
13981398
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"
13991399
integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=
14001400

1401-
chai-spies@^1.0.0:
1402-
version "1.0.0"
1403-
resolved "https://registry.yarnpkg.com/chai-spies/-/chai-spies-1.0.0.tgz#d16b39336fb316d03abf8c375feb23c0c8bb163d"
1404-
integrity sha512-elF2ZUczBsFoP07qCfMO/zeggs8pqCf3fZGyK5+2X4AndS8jycZYID91ztD9oQ7d/0tnS963dPkd0frQEThDsg==
1405-
1406-
chai@^4.2.0:
1407-
version "4.3.4"
1408-
resolved "https://registry.yarnpkg.com/chai/-/chai-4.3.4.tgz#b55e655b31e1eac7099be4c08c21964fce2e6c49"
1409-
integrity sha512-yS5H68VYOCtN1cjfwumDSuzn/9c+yza4f3reKXlE5rUg7SFcCEy90gJvydNgOYtblyf4Zi6jIWRnXOgErta0KA==
1410-
dependencies:
1411-
assertion-error "^1.1.0"
1412-
check-error "^1.0.2"
1413-
deep-eql "^3.0.1"
1414-
get-func-name "^2.0.0"
1415-
pathval "^1.1.1"
1416-
type-detect "^4.0.5"
1417-
14181401
chalk@^2.0.0, chalk@^2.3.2:
14191402
version "2.4.2"
14201403
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
@@ -1432,11 +1415,6 @@ chalk@^4.0.0, chalk@^4.1.0:
14321415
ansi-styles "^4.1.0"
14331416
supports-color "^7.1.0"
14341417

1435-
check-error@^1.0.2:
1436-
version "1.0.2"
1437-
resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.2.tgz#574d312edd88bb5dd8912e9286dd6c0aed4aac82"
1438-
integrity sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=
1439-
14401418
chokidar@3.5.1:
14411419
version "3.5.1"
14421420
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.1.tgz#ee9ce7bbebd2b79f49f304799d5468e31e14e68a"
@@ -1816,13 +1794,6 @@ decamelize@^4.0.0:
18161794
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-4.0.0.tgz#aa472d7bf660eb15f3494efd531cab7f2a709837"
18171795
integrity sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ==
18181796

1819-
deep-eql@^3.0.1:
1820-
version "3.0.1"
1821-
resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-3.0.1.tgz#dfc9404400ad1c8fe023e7da1df1c147c4b444df"
1822-
integrity sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==
1823-
dependencies:
1824-
type-detect "^4.0.0"
1825-
18261797
deep-extend@^0.6.0:
18271798
version "0.6.0"
18281799
resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.6.0.tgz#c4fa7c95404a17a9c3e8ca7e1537312b736330ac"
@@ -2574,11 +2545,6 @@ get-caller-file@^2.0.5:
25742545
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e"
25752546
integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==
25762547

2577-
get-func-name@^2.0.0:
2578-
version "2.0.0"
2579-
resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.0.tgz#ead774abee72e20409433a066366023dd6887a41"
2580-
integrity sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=
2581-
25822548
get-intrinsic@^1.0.2, get-intrinsic@^1.1.1:
25832549
version "1.1.1"
25842550
resolved "https://registry.yarnpkg.com/get-intrinsic/-/get-intrinsic-1.1.1.tgz#15f59f376f855c446963948f0d24cd3637b4abc6"
@@ -4524,11 +4490,6 @@ path-type@^4.0.0:
45244490
resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b"
45254491
integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==
45264492

4527-
pathval@^1.1.1:
4528-
version "1.1.1"
4529-
resolved "https://registry.yarnpkg.com/pathval/-/pathval-1.1.1.tgz#8534e77a77ce7ac5a2512ea21e0fdb8fcf6c3d8d"
4530-
integrity sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==
4531-
45324493
performance-now@^2.1.0:
45334494
version "2.1.0"
45344495
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
@@ -5578,7 +5539,7 @@ type-check@^0.4.0, type-check@~0.4.0:
55785539
dependencies:
55795540
prelude-ls "^1.2.1"
55805541

5581-
type-detect@4.0.8, type-detect@^4.0.0, type-detect@^4.0.5, type-detect@^4.0.8:
5542+
type-detect@4.0.8, type-detect@^4.0.8:
55825543
version "4.0.8"
55835544
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"
55845545
integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==

0 commit comments

Comments
 (0)