Skip to content

handleActions return Typing for functions not respected #230

Open
@dannycochran

Description

@dannycochran

It looks like functions in handleActions aren't properly propagating the Generic type passed in, for instance:

interface MyInterface {
  foo: number;
  bar: string;
}

const export default handleActions<MyInterface, {}>({
  [SOME_ACTION]: (state, payload) => ({
    notFoo: 'bar'
  });
});

The value return from the SOME_ACTION function should give a Typescript warning but it's not, unless you specifically type the return type in the reducer function. Looking at how handleActions is typed, though, I'm not sure why this is happening:

...
export function handleActions<State, Payload>(
    reducerMap: ReducerMap<State, Payload>,
    initialState: State
): Reducer<State, Payload>;
...
export interface ReducerMap<State, Payload> {
    [actionType: string]: Reducer<State, Payload> | ReducerNextThrow<State, Payload>;
}
...
export interface ReducerNextThrow<State, Payload> {
    next?(state: State, action: Action<Payload>): State;
    throw?(state: State, action: Action<Payload>): State;
}
...
export type Reducer<State, Payload> = (state: State, action: Action<Payload>) => State;

It seems like "MyInterface" should be properly propagated as the return type for reducer functions?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions