Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[use-debounce] Fix debounce returned function #4544

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
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();
});
});
Original file line number Diff line number Diff line change
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