Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 80dc734

Browse files
committed
Fix error with incorrect setTimeout/setInterval callback type
1 parent 9e825d4 commit 80dc734

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

packages/core/src/standards/timers.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ export function createTimer<Return>(
1414
return (callback, ms, ...args) => {
1515
if (blockGlobalTimers) assertInRequest();
1616
return func(
17-
async (...args) => {
18-
await waitForOpenInputGate();
19-
callback(...args);
20-
},
17+
callback
18+
? async (...args) => {
19+
await waitForOpenInputGate();
20+
callback?.(...args);
21+
}
22+
: callback,
2123
ms,
2224
...args
2325
);

packages/core/test/standards/timers.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ test("inputGatedSetTimeout: waits for input gate to open before calling callback
2929
});
3030
t.deepEqual(result, [42, "test"]);
3131
});
32+
test("inputGatedSetTimeout: throws without a callback", (t) => {
33+
// @ts-expect-error intentionally testing incorrect types
34+
t.throws(() => inputGatedSetTimeout(), {
35+
code: "ERR_INVALID_CALLBACK",
36+
});
37+
});
3238

3339
test("inputGatedSetInterval: calls callback with no input gate in context", async (t) => {
3440
let [trigger, promise] = triggerPromise<[number, string]>();

0 commit comments

Comments
 (0)