Skip to content

Commit

Permalink
[use-debounce] Fix debounce returned function (#4544)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brianzchen committed Oct 26, 2023
1 parent 485275a commit 119d3e4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Expand Up @@ -31,11 +31,15 @@ describe('use-debounce', () => {
1000
);

debounced('test');
// $FlowExpectedError[incompatible-call] it matches the type of the callback
debounced(123);

debounced.cancel();
debounced.flush();
debounced.isPending();

// $FlowExpectedError[prop-missing]
// $FlowExpectedError[incompatible-call]
debounced.foo();
});

Expand All @@ -51,11 +55,15 @@ describe('use-debounce', () => {
1000
);

debounced('test');
// $FlowExpectedError[incompatible-call] it matches the type of the callback
debounced(123);

debounced.cancel();
debounced.flush();
debounced.isPending();

// $FlowExpectedError[prop-missing]
// $FlowExpectedError[incompatible-call]
debounced.foo();
});
});
Expand Up @@ -37,10 +37,7 @@ declare module 'use-debounce' {
* Subsequent calls to the debounced function `debounced.callback` return the result of the last func invocation.
* Note, that if there are no previous invocations it's mean you will get undefined. You should check it in your code properly.
*/
declare type DebouncedState<R, T: (...args: any) => R> = {|
...ControlFunctions,
(...args: Parameters<T>): R | void,
|};
declare type DebouncedState<R, T: (...args: any) => R> = ControlFunctions & ((...args: Parameters<T>) => R | void);

declare module.exports: {|
useDebounce: <T>(value: T, delay: number, options?: {|
Expand Down

0 comments on commit 119d3e4

Please sign in to comment.