// Type definitions for use-reducer-with-side-effects 0.4 // Project: https://github.com/baz/foo (Does not have to be to GitHub, but prefer linking to a source code repository rather than to a project website.) // Definitions by: Chris Dhanaraj // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /*~ If this module has methods, declare them as functions like so. */ type SideEffectArguments = { state: any; dispatch: (action: object) => void; }; type SideEffectReturn = void | (() => void); type SideEffectCallback = (state: any, dispatch: SideEffectArguments) => void; type Reducer = (prevState: S, action: A) => S; type ReducerState> = R extends Reducer ? S : never; type ReducerAction> = R extends Reducer ? A : never; type Dispatch = (value: A) => void; export function UpdateWithSideEffect(newState: any, newSideEffect: SideEffectCallback): SideEffectReturn; export function NoUpdate(): Symbol; export function SideEffect(newSideEffect: SideEffectCallback): void; export function useReducerWithSideEffects, I>( reducer: R, initializerArg: I & ReducerState, initializer: (arg: I & ReducerState) => ReducerState ): [ReducerState, Dispatch>]; export function useReducer, I>( reducer: R, initializerArg: I, initializer: (arg: I) => ReducerState ): [ReducerState, Dispatch>]; export function useReducer>( reducer: R, initialState: ReducerState, initializer?: undefined ): [ReducerState, Dispatch>];