diff --git a/index.ts b/index.ts index e7a7b6c..89deea1 100644 --- a/index.ts +++ b/index.ts @@ -7,9 +7,10 @@ type ReadOnlyRefObject = { readonly current: T; }; +type UseStateRefValue = [T, Dispatch>, ReadOnlyRefObject]; type UseStateRef = { - (initialState: S | (() => S)): [S, Dispatch>, ReadOnlyRefObject]; - (): [S | undefined, Dispatch>, ReadOnlyRefObject]; + (initialState: S | (() => S)): UseStateRefValue; + (): UseStateRefValue; }; const useStateRef: UseStateRef = (initialState?: S | (() => S)) => { @@ -22,7 +23,7 @@ const useStateRef: UseStateRef = (initialState?: S | (() => S)) => { setState(ref.current); }, []); - return [state, dispatch, ref]; + return [state, dispatch, ref] as UseStateRefValue; }; export = useStateRef;