export type IHookStateInitialSetter = () => S; export type IHookStateInitAction = S | IHookStateInitialSetter; export type IHookStateSetter = ((prevState: S) => S) | (() => S); export type IHookStateSetAction = S | IHookStateSetter; export type IHookStateResolvable = S | IHookStateInitialSetter | IHookStateSetter; export function resolveHookState(nextState: IHookStateInitAction): S; export function resolveHookState( nextState: IHookStateSetAction, currentState?: C ): S; export function resolveHookState( nextState: IHookStateResolvable, currentState?: C ): S; export function resolveHookState( nextState: IHookStateResolvable, currentState?: C ): S { if (typeof nextState === 'function') { return nextState.length ? (nextState as Function)(currentState) : (nextState as Function)(); } return nextState; }