From 8429bef564f6e6c7e605ce2018e2a98bff199835 Mon Sep 17 00:00:00 2001 From: Samuel Hoffstaetter Date: Tue, 21 May 2024 15:50:09 -0700 Subject: [PATCH] Fix type declaration for flush(). The `flush()` function returns the result of the most recent function invocation, however, the type declaration did not reflect this correctly. This commit updates the Typescript declaration to match the actual return-type of the function. --- src/useDebouncedCallback.ts | 6 +++--- test/useDebouncedCallback.test.tsx | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/useDebouncedCallback.ts b/src/useDebouncedCallback.ts index f45f48e..dd92325 100644 --- a/src/useDebouncedCallback.ts +++ b/src/useDebouncedCallback.ts @@ -22,7 +22,7 @@ export interface Options extends CallOptions { debounceOnServer?: boolean; } -export interface ControlFunctions { +export interface ControlFunctions { /** * Cancel pending function invocations */ @@ -30,7 +30,7 @@ export interface ControlFunctions { /** * Immediately invoke pending function invocations */ - flush: () => void; + flush: () => ReturnT | undefined; /** * Returns `true` if there are any pending function invocations */ @@ -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 ReturnType> - extends ControlFunctions { + extends ControlFunctions> { (...args: Parameters): ReturnType | undefined; } diff --git a/test/useDebouncedCallback.test.tsx b/test/useDebouncedCallback.test.tsx index e8f215f..23a9658 100644 --- a/test/useDebouncedCallback.test.tsx +++ b/test/useDebouncedCallback.test.tsx @@ -500,7 +500,7 @@ describe('useDebouncedCallback', () => { debounced(); useEffect(() => { - return debounced.flush; + return () => { debounced.flush(); }; }, []); return {text}; }