Skip to content

Commit

Permalink
fix node:timers types (#3386)
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb authored Jan 21, 2025
1 parent 6dd8a1a commit 19b9a9b
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/node/internal/internal_timers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,25 @@ export class Timeout {
}
}

export function setTimeout(
callback: (...args: unknown[]) => unknown,
after: number,
...args: unknown[]
export function setTimeout<TArgs extends unknown[]>(
callback: (...args: TArgs) => unknown,
delay?: number,
...args: TArgs
): Timeout {
validateFunction(callback, 'callback');

return new Timeout(
callback,
after,
delay,
args,
/* isRepeat */ false,
/* isRefed */ true
);
}

export function clearTimeout(timer: unknown): void {
export function clearTimeout(
timer: Timeout | string | number | undefined
): void {
if (timer instanceof Timeout) {
clearTimeoutImpl(timer);
} else if (typeof timer === 'number') {
Expand All @@ -139,10 +141,10 @@ export const setImmediate = timersUtil.setImmediate.bind(timersUtil);

export const clearImmediate = timersUtil.clearImmediate.bind(timersUtil);

export function setInterval(
callback: (...args: unknown[]) => void,
repeat: number,
...args: unknown[]
export function setInterval<TArgs extends unknown[]>(
callback: (...args: TArgs) => void,
repeat?: number,
...args: TArgs
): Timeout {
validateFunction(callback, 'callback');
return new Timeout(
Expand All @@ -154,7 +156,9 @@ export function setInterval(
);
}

export function clearInterval(timer: unknown): void {
export function clearInterval(
timer: Timeout | string | number | undefined
): void {
if (timer instanceof Timeout) {
clearTimeoutImpl(timer);
} else if (typeof timer === 'number') {
Expand All @@ -165,7 +169,7 @@ export function clearInterval(timer: unknown): void {
/**
* @deprecated Please use timeout.refresh() instead.
*/
export function active(timer: unknown): void {
export function active(timer: Timeout | string | number | undefined): void {
if (timer instanceof Timeout) {
timer.refresh();
}
Expand Down

0 comments on commit 19b9a9b

Please # to comment.