Skip to content

Commit

Permalink
Merge pull request #173 from shortstorybox/master
Browse files Browse the repository at this point in the history
Fix type declaration for flush()
  • Loading branch information
xnimorz authored May 24, 2024
2 parents bcdcf77 + 8429bef commit 126b911
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/useDebouncedCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ export interface Options extends CallOptions {
debounceOnServer?: boolean;
}

export interface ControlFunctions {
export interface ControlFunctions<ReturnT> {
/**
* Cancel pending function invocations
*/
cancel: () => void;
/**
* Immediately invoke pending function invocations
*/
flush: () => void;
flush: () => ReturnT | undefined;
/**
* Returns `true` if there are any pending function invocations
*/
Expand All @@ -42,7 +42,7 @@ export interface ControlFunctions {
* Note, that if there are no previous invocations you will get undefined. You should check it in your code properly.
*/
export interface DebouncedState<T extends (...args: any) => ReturnType<T>>
extends ControlFunctions {
extends ControlFunctions<ReturnType<T>> {
(...args: Parameters<T>): ReturnType<T> | undefined;
}

Expand Down
2 changes: 1 addition & 1 deletion test/useDebouncedCallback.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ describe('useDebouncedCallback', () => {

debounced();
useEffect(() => {
return debounced.flush;
return () => { debounced.flush(); };
}, []);
return <span role="test">{text}</span>;
}
Expand Down

0 comments on commit 126b911

Please sign in to comment.