Skip to content

[Typescript] Reducer definition causes Typescript to fall with error #2424

@miraage

Description

@miraage

Redux: 3.6.0
Typescript: 2.3.3
compilerOptions.noImplicitAny is set to true.

Redux has next definitions.

export interface Action {
  type: any;
}

export type Reducer<S> = <A extends Action>(state: S, action: A) => S;

Reducer:

interface AuthReducerState {
  user?: {
    id: number;
    email: string;
  };
}

export const authReducer: Reducer<AuthReducerState> = (state, action) => {
  switch (action.type) {
    default:
      return state;
  }
};

Errors:

TS7006: Parameter 'state' implicitly has 'any' type.
TS7006: Parameter 'action' implicitly has 'any' type.

If definitons would have been changed it would solve problem.

export interface Action {
  type: string;
  [key: any]: any;
}

export type Reducer<S> = (state: S, action: Action) => S;

Please explain what I do wrong.

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