Incorrect return type for flush() function
Closed this issue · 4 comments
h commented
Describe the bug
The type declaration of the onDebouncedCallback flush()
function claims that the return type is void
. However, that's incorrect: the actual return type is the same as the callback. (Or undefined
if the callback has never been called yet.) This causes Typescript errors when using flush()
.
To Reproduce
const foo = useDebouncedCallback(() => 'abc', 500);
foo();
const result: string | undefined = foo.flush();
results in:
foobar.tsx:31:11 - error TS2322: Type 'void' is not assignable to type 'string | undefined'.
31 const result: string | undefined = foo.flush();
Expected behavior
Typescript type declaration should match the function's actual type.
use-debounce version: 10.0.0
xnimorz commented
Merged, I'll cut a new version shortly
xnimorz commented
Published use-debounce@10.0.1