Skip to content

TypeScript: Can't use strict custom Action types any more #2516

Closed
@sbuzonas

Description

@sbuzonas

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
TypeScript declarations extending Action are broken because the Reducer type requires action to be AnyAction.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar.

const CALL_HISTORY_METHOD: string = "something";

interface RouterAction extends Action {
  type: typeof CALL_HISTORY_METHOD;
  payload: any;
}

interface RouterState { }

interface State {
  router: RouterState;
}

function routerReducer(state?: RouterState, action?: RouterAction): RouterState { }

const reducers: Reducer<State> = combineReducers({router: routerReducer});

What is the expected behavior?
I should be able to strictly type the action my reducer expects.

Which versions of Redux, and which browser and OS are affected by this issue? Did this work in previous versions of Redux?
This has worked since 3.4.0. (Some vague indication that 3.0.8, but no idea where the types came from prior to 3.4)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions