diff --git a/types/k6/experimental/timers.d.ts b/types/k6/experimental/timers.d.ts index bd95fd97aca540..44a931571d5e65 100644 --- a/types/k6/experimental/timers.d.ts +++ b/types/k6/experimental/timers.d.ts @@ -3,7 +3,7 @@ */ /** - * Set a timer which execution a function once the timer expires. + * Set a timer that executes a function once the timer expires. * * @param functionRef - The function to be executed. * @param delay - The delay in milliseconds. @@ -13,7 +13,7 @@ export function setTimeout(functionRef: (...args: any[]) => void, delay: number, ...args: any[]): TimeoutID; /** - * Cancels a timeout previously set with setTimeout(). + * Cancels a timer previously set with setTimeout(). * * @param timeoutID - The timer id to be cancelled. */ @@ -30,7 +30,7 @@ export function clearTimeout(timeoutID: TimeoutID): void; export function setInterval(functionRef: (...args: any[]) => void, delay: number, ...args: any[]): IntervalID; /** - * Cancels a interval previously set with setInterval(). + * Cancels an interval previously set with setInterval(). * * @param intervalID - The interval id to be cancelled. */ diff --git a/types/k6/index.d.ts b/types/k6/index.d.ts index 294bdd6bbfe8c7..d2666f2d064643 100644 --- a/types/k6/index.d.ts +++ b/types/k6/index.d.ts @@ -36,6 +36,7 @@ import "./experimental/tracing"; import "./experimental/webcrypto"; import "./experimental/websockets"; import "./experimental/grpc"; +import "./timers"; import "./ws"; import "./net/grpc"; diff --git a/types/k6/test/timers.ts b/types/k6/test/timers.ts index 6183d425663757..2bcf3ffe89955e 100644 --- a/types/k6/test/timers.ts +++ b/types/k6/test/timers.ts @@ -1,4 +1,4 @@ -import { clearInterval, clearTimeout, setInterval, setTimeout } from "k6/experimental/timers"; +import { clearInterval, clearTimeout, setInterval, setTimeout } from "k6/timers"; // setTimeout diff --git a/types/k6/timers.d.ts b/types/k6/timers.d.ts new file mode 100644 index 00000000000000..44a931571d5e65 --- /dev/null +++ b/types/k6/timers.d.ts @@ -0,0 +1,47 @@ +/** + * This module provides setInterval, setTimeout and co. + */ + +/** + * Set a timer that executes a function once the timer expires. + * + * @param functionRef - The function to be executed. + * @param delay - The delay in milliseconds. + * @param args - The arguments to be passed to the function. + * @returns The timer id. + */ +export function setTimeout(functionRef: (...args: any[]) => void, delay: number, ...args: any[]): TimeoutID; + +/** + * Cancels a timer previously set with setTimeout(). + * + * @param timeoutID - The timer id to be cancelled. + */ +export function clearTimeout(timeoutID: TimeoutID): void; + +/** + * Repeatedly execute a function, with a fixed time delay between each call. + * + * @param functionRef - The function to be executed. + * @param delay - The delay in milliseconds. + * @param args - The arguments to be passed to the function. + * @returns The interval id. + */ +export function setInterval(functionRef: (...args: any[]) => void, delay: number, ...args: any[]): IntervalID; + +/** + * Cancels an interval previously set with setInterval(). + * + * @param intervalID - The interval id to be cancelled. + */ +export function clearInterval(intervalID: IntervalID): void; + +/** + * Type alias for a timer id. + */ +export type TimeoutID = number; + +/** + * Type alias for a interval id. + */ +export type IntervalID = number;