Skip to content

Commit

Permalink
fix(useTimeoutFn): respect callback parameters in start function (#2693)
Browse files Browse the repository at this point in the history
  • Loading branch information
wvffle committed Jan 29, 2023
1 parent 77287e6 commit e054a24
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions packages/shared/useTimeoutFn/index.ts
Expand Up @@ -20,11 +20,11 @@ export interface UseTimeoutFnOptions {
* @param interval
* @param options
*/
export function useTimeoutFn(
cb: (...args: unknown[]) => any,
export function useTimeoutFn<CallbackFn extends(...args: any[]) => any>(
cb: CallbackFn,
interval: MaybeComputedRef<number>,
options: UseTimeoutFnOptions = {},
): Stoppable {
): Stoppable<Parameters<CallbackFn> | []> {
const {
immediate = true,
} = options
Expand All @@ -45,7 +45,7 @@ export function useTimeoutFn(
clear()
}

function start(...args: unknown[]) {
function start(...args: Parameters<CallbackFn> | []) {
clear()
isPending.value = true
timer = setTimeout(() => {
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/utils/types.ts
Expand Up @@ -97,7 +97,7 @@ export interface Pausable {
resume: Fn
}

export interface Stoppable {
export interface Stoppable<StartFnArgs extends any[] = any[]> {
/**
* A ref indicate whether a stoppable instance is executing
*/
Expand All @@ -111,7 +111,7 @@ export interface Stoppable {
/**
* Start the effects
*/
start: Fn
start: (...args: StartFnArgs) => void
}

/**
Expand Down

0 comments on commit e054a24

Please sign in to comment.